how to get projectID value from dictionary in python? [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
need to extract projectID and my final output is to be 1868117666669.
'{
"code":"ok",
"job":{
"config":{
"progress":{
"message":"Reading 2014-03-03__12-57-01-PM.xml",
"percent":107,
"maxmemory":954,
"memory":667
},
"projectID":1868117666669,
# other stuff
}
}
}'

You can try
>>> a = '{"code":"ok","job":{"config":{"progress":{"message":"Reading 2014-03-03__12-57-01-PM.xml","percent":107, "maxmemory":954,"memory":667},"projectID":1868117666669}}}'
>>> json.loads(a)['job']['config']['projectID']
1868117666669

Related

python handle json list format to array list [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
use python 3.6
this json: [["10000000000"], ["12000000000"]]
i want get like result like
"data": {"calleeInfo": [{"phone": "10000000000",},{"phone": "12000000000",}]}
By list generation
temp = [["10000000000"], ["12000000000"]]
value = [{"phone": i[0]} for i in temp]
result = {"data": {"calleeInfo": value}}
print(result)
Output
{'data': {'calleeInfo': [{'phone': '10000000000'}, {'phone': '12000000000'}]}}

convert a list of dictionary in given format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Input_data=[{​​​'filename':'file_A','start_page':1,'end_page':3,'angle':90}​​​,{'filename':'file_A','start_page':6,'end_page':8,'angle':270}​​​,{'filename':'file_B','start_page':2,'end_page':3,'angle':90}​​​,{'filename':'file_B','start_page':5,'end_page':5,'angle':270}​​​]
output=[{​​​'filename':'file_A','page':1,'angle':90}​​​,
{​​​'filename':'file_A','page':2,'angle':90}​​​,{​​​'filename':'file_A','page':3,'angle':90}​​​,{​​​'filename':'file_A','page':6,'angle':270}​​​,{​​​'filename':'file_A','page':7,'angle':270}​​​,
{​​​'filename':'file_A','page':8,'angle':270}​​​,{​​​'filename':'file_B','page':2,'angle':90}​​​,
{​​​'filename':'file_B','page':3,'angle':90}​​​,{​​​'filename':'file_B','page':5,'angle':270}​​​]
}
If I understood correctly, you want to do:
output = []
for d in Input_data:
for i in range(d["start_page"], d["end_page"] + 1):
output.append({'filename':d["filename"], 'page':i, 'angle':d["angle"]})
print(output)

string concatination at specificv value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
these items are in a list
SF-04-08-010-MD01,
AHU-VVIP-02-003-MD03,
AHU-02-17-019-DPS03,
AHU-T3-01-PL-TS01,
EF-03-32-108-MD01,
AHU-02-16-019-MD01,
AHU-T3-01-003-MD01,
SF-04-08-010-MD01,
AHU-VVIP-02-003-MD03,
so i want a new list which should be like
SF-04-08
AHU-VVIP
AHU-02-17
AHU-T3-01
EF-03-32
AHU-02-16
AHU-T3-01
SF-04-08
AHU-VVIP-02
using python??
you can use strip like:
data = ['SF-04-08-010-MD01',
'AHU-VVIP-02-003-MD03',
'AHU-02-17-019-DPS03'
]
for item in data:
print ('-'.join(item.split('-')[:3]))
output:
SF-04-08
AHU-VVIP-02
AHU-02-17

Convert String to json python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have this type of string given by my lambda function
aws-internal/3 aws-sdk-java/1.11.432
Linux/4.9.124-0.1.ac.198.71.329.metal1.x86_64
OpenJDK_64-Bit_Server_VM/25.181-b13 java/1.8.0_181
Now i want to convert this string into Json like
{
aws-internal:3,
aws-sdk-java:1.11.432,
Linux:/4.9.124-0.1.ac.198.71.329.metal1.x86_64
}
Please Give me a suggestion i search many website and library
You can do that with something like:
items = dict(a.split('/') for a in a_string.split())
Test Code:
a_string='aws-internal/3 aws-sdk-java/1.11.432 Linux/4.9.124-0.1.ac.198.71.329.metal1.x86_64 OpenJDK_64-Bit_Server_VM/25.181-b13 java/1.8.0_181'
items = dict(a.split('/') for a in a_string.split())
print(items)
Results
{
'aws-internal': '3',
'aws-sdk-java': '1.11.432',
'Linux': '4.9.124-0.1.ac.198.71.329.metal1.x86_64',
'OpenJDK_64-Bit_Server_VM': '25.181-b13',
'java': '1.8.0_181'
}

Variable as part of the generated filename [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Example:
var = "string"
and I want an xml output file: string.xml
Thank you!
It seams to be too easy... maybe i did not get the question right:
var = "String"
fileName = var + ".xml"
print fileName
this will print
String.xml

Categories

Resources