[Tutor] Editing values from a dictionary

Bob Williams linux at barrowhillfarm.org.uk
Wed Feb 26 18:48:49 CET 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 26/02/14 17:29, Ben Finney wrote:
> Bob Williams <linux at barrowhillfarm.org.uk> writes:
> 
>> In [3]: print metadata["artist"] [u'The Incredible String Band']
>> 
>> I now want to pass that string to another program, but I want to
>> strip off the leading [u' and the trailing '].
> 
> You may be assuming that ‘metadata["artist"]’ is a text string; I 
> suspect it is not.
> 
> Try ‘type(metadata["artist"])’, to get Python to tell you what the
> type of that object is.
> 
Aha! Sounds of pennies dropping ;-)

In [7]: type(metadata["artist"])
Out[7]: list

In [12]: print metadata["artist"][0]
The Incredible String Band

Gets me what I want. Thank you.

Bob
- -- 
Bob Williams
System:  Linux 3.11.10-7-desktop
Distro:  openSUSE 13.1 (x86_64) with KDE Development Platform: 4.12.2
Uptime:  12:00pm up 13 days 20:00, 6 users, load average: 0.10, 0.19, 0.26
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlMOKP8ACgkQ0Sr7eZJrmU5a0ACdEH9kJPtHmbQ9w8YXrUc3NJT1
/t8AnitS+J4+kcM2z+Ai6Ak7cbe7Qnmk
=Sv8P
-----END PGP SIGNATURE-----


More information about the Tutor mailing list