python - Output specific value from Json object retrieved from external function -


i'm having trouble getting proper output value when doing

print metadata["file:filesize"] 

it gives me list indices must integer, not str error. thought json.loads returns dictionary.

the variable metadata retrieved exiftool in class such:

def get_metadata(self, *filenames):     return json.loads(self.execute("-g", "-j", "-n", *filenames)) 

and in main program flow this:

metadata = exif.get_metadata(filename) print metadata print metadata["file:filesize"] 

can me figure out doing wrong?

here sample of raw exiftool query:

[{   "sourcefile": "/media/mango/mf-hdd-277/01_audio/computer arts royalty-free audio samples/disc 191 - soundsnap/computerartsdisc191_soundsnapsamples_088_bend03.wav",   "exiftool:exiftoolversion": 9.13,   "file:filename": "computerartsdisc191_soundsnapsamples_088_bend03.wav",   "file:directory": "/media/mango/mf-hdd-277/01_audio/computer arts royalty-free audio samples/disc 191 - soundsnap",   "file:filesize": 146948,   "file:filemodifydate": "2010:10:24 11:17:20-04:00",   "file:fileaccessdate": "2014:01:29 15:58:48-05:00",   "file:fileinodechangedate": "2014:01:21 13:28:00-05:00",   "file:filepermissions": 711,   "file:filetype": "wav",   "file:mimetype": "audio/x-wav",   "riff:encoding": 1,   "riff:numchannels": 2,   "riff:samplerate": 44100,   "riff:avgbytespersec": 176400,   "riff:bitspersample": 16,   "composite:duration": 0.833038548752834 }] 

the raw query returning javascript object inside array. when parse json json.loads, dict inside list. so, access attributes, metadata[0]["file:filesize"].

or change get_metadata method directly return dict.

def get_metadata(self, *filenames):     return json.loads(self.execute("-g", "-j", "-n", *filenames))[0] 

and no, json.loads not returns dictionaries. table tim linked in comment specifies json python translations.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -