Getting The Value From Text File After The Colon Or Before The Colon In Python
I only need the last number 25 so i can change it to int(). I have this text file: { 'members': [ {'name': 'John', 'location': 'QC', 'age': 25}, {'name': 'Jesse', 'locat
Solution 1:
I'm not sure what you're asking how to do, but will make an attempt to guess.
First of all, the text you show isn't valid JSON and would need to be changed to something like this:
{
"members": [
{"name": "John", "location": "QC", "age": 25},
{"name": "Jesse", "location": "PQ", "age": 24}
]
}
Here's something that would print out all the data for each member in location PQ
:
import json
import pprint
my_data = json.loads(open("team.json.txt").read())
members_in_pq = [member for member in my_data['members']
if member['location'] == 'PQ']
print 'members whose location is in PQ'
for member in members_in_pq:
print ' name: {name}, location: {location}, age: {age}'.format(**member)
Output:
members whose location is in PQ
name: Jesse, location: PQ, age: 24
Post a Comment for "Getting The Value From Text File After The Colon Or Before The Colon In Python"