0

I have this dictionary called audio that displays information about MP3 files in unicode. I used str() to turn the album and title values into strings.

alb = []
trck = []
audio = MP3(fullname)

albums = (str(audio['TALB'])) #TALB is the album key
tracks = (str(audio['TIT2'])) #Track key
trck = trck.append(tracks)
alb = alb.append(album)

When I print the result after the sixth line, it dumps out all the album and tracks titles of 5000+ songs. After that, I'd like to add the tracks and albums to separate lists so I use append() however I get an error. Are there any alternatives? Also I've tried creating a list straight from the dict using .iteritem() but all the values are in unicode so it's harder to organize. Plus, it creates a separate array for each .mp3 file.

I'm relatively new to Python so any help regarding my issue would be appreciated.

MORE INFO:

The audio dictionary gives me about 5000+ lines of something looking like this when I print it out:

{'TDRC': TDRC(encoding=3, text=[u'1993']), 'TIT2': TIT2(encoding=3, text=[u'All I Wanna     Do']), 'TRCK': TRCK(encoding=3,
text=[u'9']), 'TPE1': TPE1(encoding=3, text=[u'Sheryl Crow']), 'TALB': TALB(encoding=3,     text=[u'Tuesday Night Music Club
']), 'TSSE': TSSE(encoding=3, text=[u'Xiph.Org libVorbis I 20070622']), 'TCON':     TCON(encoding=3, text=[u'Rock'])}

So after using str() on say, all the TIT2 keys, printing it out gives me only the values of every TIT2 key in the audio dictionary.

Tricky Kid
Vent
A Groovy Kind Of Love
Do You know The Way To San Jose?
Jamaica
I (Who Have Nothing)
River Deep - Mountain High
Spanish Harlem
Ten Lonely Guys
Will You Love Me Tomorow
Cry
In The Sand
Michel
My Friend
The Dark
Let It Ride
Urban Solitude
Be A Man

And so on. Next, I try to append these results to the empty list trck[].

trck.append(tracks)
print trck

When I print it out, I get this:

['Tricky Kid']
['Vent']
['A Groovy Kind Of Love']
['Do You know The Way To San Jose?']
['Jamaica']
['I (Who Have Nothing)']
['River Deep - Mountain High']
['Spanish Harlem']
['Ten Lonely Guys']
['Will You Love Me Tomorow']
['Cry']
['In The Sand']
['Michel']
['My Friend']
['The Dark']
['Let It Ride']
['Urban Solitude']
['Be A Man']

When I print track[0], it gives me all 5000 songs and trck[1] is out of range. How can I fix this?

3
  • You have lists, not arrays.. there is a array module in Python as well. Commented Oct 4, 2013 at 23:47
  • What error do you get? Commented Oct 4, 2013 at 23:48
  • @Martjin Aah ! I congratulate you for your very good first comment. I'm happy to see someone paying attention to precision of terms. Commented Oct 6, 2013 at 13:36

1 Answer 1

3

The append method of a list modifies the list in place and returns None. Drop the assignment when you use append, ie use trck.append(tracks) instead of trck = trck.append(tracks), otherwise the variable gets assigned to None and you lose your list.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but now I have this list where list[0] corresponds to all of the album titles. How can I make it so each album title takes a position of list(n)?
Maybe instead of append you want something like trck = list(tracks), but it's really had to know without more information about how your data is organized. If you could add some example data to your question it would really help. In general you'll get better answers on SO if you include working code that reproduces your error or issue and a small data set if it's relevant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.