Now that we know RJ, what are his favourite artists? Let's have a look:
>>> import lastfm >>> profile = lastfm.user.profile_information("RJ") >>> artists_xml = profile.top_artists(format=lastfm.FORMAT.xml) >>> print artists_xml <?xml version="1.0" encoding="UTF-8"?> <topartists user="RJ"> <artist> <name>Dream Theater</name> <mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid> <playcount>837</playcount> <rank>1</rank> <url>http://www.last.fm/music/Dream+Theater</url> <thumbnail>http:///storable/image/153635/small.jpg</thumbnail> <image>http://static.last.fm/proposedimages/sidebar/6/4209/432600.jpg</image> </artist> .... <artist> <name>The Doors</name> <mbid>9efff43b-3b29-4082-824e-bc82f646f93d</mbid> <playcount>140</playcount> <rank>49</rank> <url>http://www.last.fm/music/The+Doors</url> <thumbnail>http:///storable/image/148057/small.jpg</thumbnail> <image>http://static.last.fm/proposedimages/sidebar/6/344/408886.jpg</image> </artist> </topartists> >>>
Uh, Dream Theater at rank 1 and The Doors as last...Ok, it's not my profile.
Again, let's get a little more pythonic:
>>> artists = profile.top_artists() >>> artists <<< <TopArtists username='RJ'> >>> for artist in artists: ... print artist.rank, artist.name ... ... 1 Dream Theater 2 Miles Davis 3 Aerosmith >>>
You can get the same result without creating a Profile instance by calling the lastfm.user.top_artists function directly:
>>> artists = lastfm.user.top_artists("RJ") >>> artists <<< <TopArtists username='RJ'> >>>