Looking For mp3 ID Tag Module

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Aug 18 03:51:26 EDT 2006


[Tim Daneliuk]
| >> audio["title'] = Something based on the filename that has unicode 
| >> chars in it

| >>
| >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc 
| in position 
| >> 56: ordinal not in range(128)

| I am trying to set the title based on the filename.  The file 
| is in a Win32
| NTFS filesystem, so it could have non-ASCII chars in it.  
| What I am stumbling
| on it how to coerce it into unicode.  I have tried:

How are you getting the filename? If it's os.listdir,
try passing the path name as a unicode string:

import os
filenames = os.listdir (u".")

This will return a list of unicode strings, which you can
then decode at will or pass along direct.

If you're using, say, glob which doesn't return
Unicode, I suggest you try decoding via
sys.stdin.encoding (cp437 on my machine) or
cp1252, which is commonly used under (Western) Windows.

I'm sure there is some more canonical way of getting
the encoding the filesystem has returned, but I'm
afraid I've no idea what it is. Best bet is probably
the listdir (u".") approach.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list