Python JIRA script help

I have written a simple python script to query jira …

from jira import JIRA

jiraurl = "https://myjira.com"
username = "un"
password = "pw"

class MyJira:
    def __init__(self, server_url, username, password):
        self.jira = JIRA(server_url, basic_auth=(username. password))

    def query(self, jql):
        issues = self.jira.search_issues(jql)
        return issues

jira_query = MyJira(jiraurl, username, password)
issues = jira_query.query(jql_query)
print(issues)
my_list = []
for issue in issues:
    print(issue)
    my_list.append(issue)

print(my_list)

here is the output of print(issues):

[<JIRA Issue: key='PBI-12345', id='1375672'>,<JIRA Issue: key='PBI-12346', id='1375872>,<JIRA Issue: key='PBI-12349', id='1376672>]

here is the output of print(issue)

PBI-12345
PBI-12346
PBI-12349

and here is the output of print(my_list)

[<JIRA Issue: key='PBI-12345', id='1375672'>,<JIRA Issue: key='PBI-12346', id='1375872>,<JIRA Issue: key='PBI-12349', id='1376672>]

when i did the first print(issues);
is my output a dictionary ?
with the following objects:
<JIRA Issue: key=‘PBI-12345’, id=‘1375672’>,
<JIRA Issue: key=‘PBI-12346’, id='1375872>,
<JIRA Issue: key=‘PBI-12349’, id='1376672>

when i give my 2nd print statement print(issue):
should it not be printing the objects ? why is it printing just the ticket number like so
PBI-12345
PBI-12346
PBI-12349

when i’m printing my 3rd print statement: here is what i’m expecting
[‘PBI-12345’, ‘PBI-12346’, ‘PBI-12349’]
but why is it printing this output?
[<JIRA Issue: key=‘PBI-12345’, id=‘1375672’>,<JIRA Issue: key=‘PBI-12346’, id='1375872>,<JIRA Issue: key=‘PBI-12349’, id='1376672>]

I have also tried using my_list.append(issue["key"])
but i get a TypeError:‘Issue’ object is not subscriptable

I have written a simple python script to query jira …

[...]
issues = jira_query.query(jql_query)
print(issues)
my_list = []
for issue in issues:
   print(issue)
   my_list.append(issue)
print(my_list)

here is the output of print(issues):

[<JIRA Issue: key='PBI-12345', id='1375672'>,<JIRA Issue: key='PBI-12346', id='1375872>,<JIRA Issue: key='PBI-12349', id='1376672>]

The issues variable lookslike it already contains a list of JIRA issue
instances.

here is the output of print(issue)

PBI-12345
PBI-12346
PBI-12349

Right.

and here is the output of print(my_list)

[<JIRA Issue: key='PBI-12345', id='1375672'>,<JIRA Issue: key='PBI-12346', id='1375872>,<JIRA Issue: key='PBI-12349', id='1376672>]

Also a list of JIRA issues instances.

when i did the first print(issues);
is my output a dictionary ?

No, it’s the string representation of a list: [jiraobj,jiraobj,].

When you want to present a Python object as a string there are 2
predefined functions for the easy things (as opposed to arbitrary more
thorough complicate things you might make yourself): str and repr.

str(obj) presents the human friendly version. FOr a JIRA object it
looks like the JIRA bug id: PBI-12345.

repr(obj) presents, notionally, a more detailed version. Sometimes a
valid Python expression, but not in this case:
<JIRA Issue: key='PBI-12345', id='1375672'>.

You’ll see this layout relatively common names, typically <type details>.

When you call print(obj), the print function calls str on each
argument. So when you go:

 print(issue)

you get str(issue) as the output text, thus PBI-12345.

Python classes get to define what these functions do by defining
__str__ and __repr__ methods.

When you call print(issues) you get str() for a list, which as it
happens looks just like repr() for the list. In particular, each
element of the list is rendered with repr(), not str().

You can get prettier output in various ways, depending what you want.
One easy way is this:

 print(*issues)

This is Python’s “unpacking” syntax. Instead of passing issues as a
single argument to print(), so that it prints str(issues), this
passes each element of issues as a separate argument, and print()
calls str() on each argument individually. So you’ll get the nice
str(issue) style output.

Cheers,
Cameron Simpson cs@cskk.id.au

I expect that the issue object has implements the __str__ dunder to print the issue number only. Where as its __repr__ method prints the debug info you see.

Suggest you read the source code of the JIRA class to understand its implementation.