this post was submitted on 12 Jan 2024
15 points (100.0% liked)

Python

6378 readers
80 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

In my file, I have

from mutagen.id3 import ID3
tags = ID3(mp3_file)

Now if I do print(tags.keys())

It informs me that there's a TXXX:FMPS_Rating_Amarok_Score

But when I attempt to print(tags["TXXX:FMPS_Rating_Amarok_Score"])

It says there's a KeyError. What am I doing wrong?

you are viewing a single comment's thread
view the rest of the comments
[–] ggwithgg@feddit.nl 8 points 10 months ago (3 children)

I suspect your 'tags' is not a dict object, but some extension of it. Lookup its type, or the documentation of the library you are using for how to retrieve values from an ID3 object.

[–] jnovinger@programming.dev 3 points 10 months ago (2 children)

Looking at the docs, it looks like it's an instance of ID3Tags, which appears to be based on couple of helper classes mutagen._util.DictProxy and mutagen._tags.Tags, where DictProxy (and its base DictMixin) provides the dict-like interface. Underneath that, it looks like it's storing the actual values in a simple dict (DictProxy.__dict) and proxying to that.

I'm not seeing anything obvious that would muck with the incoming lookup key anywhere in ID3Tags or DictProxy.__getitem__ or any of the other base classes.

I have to jump off to pack for a trip, but might try this out later in a live shell session to see if there's something odd going on with the API.

In the meantime, OP, are you positive you were looking at the same file each time? Was this in a script or in a live Python shell session?

[–] sabreW4K3@lemmy.tf 1 points 10 months ago

For testing purposes, same file every time, this one: https://file.coffee/u/IxKmfKfUwgPybq_vv8YJc.mp3

load more comments (1 replies)
load more comments (1 replies)