Python Forum
Question about working with dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about working with dictionaries
#1
Question 
Hello forum,

I am having the current hurdle working with dictionaries.
Concrete: I am trying to add variable amounts of components to a JIRA issue.

Example:
If "Linux" is selected, I want to have the distribution added as second component as well.
Result in components: "Linux", "Mint"

JIRA required to have the following structure
[{ "name" : "component" }]
or for multiple components
[{ "name" : "component" }, { "name" : "component" }]
What works is something like:
[{ "name" : VARIABLE }]
or
[{ "name" : VARIABLE }, { "name" : SECOND_VARIABLE }]
What is now my problem:
I need to have this structure depending on what is selected before as having empty variables is not valid for the cases having only one component.

If e.g. "Windows" is selected I want to have this structure:
[{ "name" : VARIABLE }]
and if "Linux" is selected, I want to have this structure:
[{ "name" : VARIABLE }, { "name" : SECOND_VARIABLE }]
Filling the variables is no issue at all, only "building" the dictionaries within if-clauses beforehand and moving them as variable in this structure is an issue.

I tried the following:

if var_LinuxDistro == 1:
  components_list = '{ "name" : "Linux" }, { "name" : "'+VARIABLE+'" }'

else:
  components_list = '{ "name" : "'+VARIABLE+'" }'
and took this components to the creation part:

issue_dict = {
    'project': {'key': 'Project'},
    'summary': 'Testing issue from Python',
    'description': 'Ticket description.',
    'issuetype': {'name': 'Issue'},
    'components': [components_list],
}
Leading to an error
response text = {"errorMessages":[],"errors":{"components":"expected Object"}}

How can I get this fixed?


If this is necessary, here is an example how to import an issue to JIRA with python

issue_dict = {
    'project': {'key': 'Project'},
    'summary': 'Testing issue from Python',
    'description': 'Ticket description.',
    'issuetype': {'name': 'Issue'},
    'components': [{'name': 'Issue'}, {'name': 'Issue'}],
}

new_issue = jira_connection.create_issue(fields=issue_dict)
Reply


Messages In This Thread
Question about working with dictionaries - by Ashcora - Dec-24-2022, 09:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Quick Question about Dictionaries Extra 6 3,109 Apr-29-2022, 08:34 PM
Last Post: Extra
  Noob question: why is shapesize() not working for my turtle adifrank 8 9,495 Sep-09-2020, 11:13 PM
Last Post: adifrank
  Working with files and dictionaries OmarSinno 1 3,322 Oct-30-2017, 11:02 AM
Last Post: wavic
  Working with dictionaries and keys netrate 9 7,663 Jun-01-2017, 05:29 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020