[Tutor] UnicodeDecodeError when copying files with Umlauten

2005-07-09 Thread Severin Kacianka
Hello, 

I am very new to python programming and totally new to GUI-programming. Now I 
try to write a GUI for a little script I wrote some time ago, and get a Error 
I cannot explain. 
As it may be helpful for you to see the whole scripts I put them both online:
The CLI-application (and library): http://kacianka.at/python/m3u2iso.py
The GUI-code: http://kacianka.at/python/win.py

The script essentially copies files listed in a m3u file into a given 
directory. The essential line in the library is line 95:

shutil.copyfile(file,'%s%s'% (self.tmpDir,self.currentFile ))

Now there is no problem with "normal" files, but if I try to copy a file with 
German Umlauten (ä,ü,ö,ß) a UnicodeDecodeError is triggered in this GUI-Code:

def OnConvert(self,event):
"""Starts everything"""
m2i = m3u2iso.m3uToIso(self.m3uPath,self.tmpDir)
if DEBUG:
print "m3u2iso::m3uPath: %s" % m2i.m3uPath
print "m3u2iso::tmpDir: %s"  % m2i.tmpDir
m2i.getSongPath()
m2i.cpFilesToTmpDir(self.shortFileNames,self.verbose,self.start)

If I run the script on the CLI, it always works, no matter if the files 
contain Umlaute or not. However if I do the same thing with the GUI I get 
this error:

Traceback (most recent call last):
  File "./win.py", line 132, in OnConvert
m2i.cpFilesToTmpDir(self.shortFileNames,self.verbose,self.start)
  File "/home/severin/python/m3u2iso.py", line 100, in cpFilesToTmpDir
print "Unicode Error n trying to copy %s to %s%s" % 
(file,self.tmpDir,self.currentFile )
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 23: 
ordinal not in range(128)

This happens when I try to copy a file called "Kettcar - Landungsbrücken 
raus.mp3". 
I cannot explain to myself why this happens in the GUI but not in the CLI 
version. The code is the same! 

Is there an obvious error in my code, or do I maybe totally missunderstand the 
concept of handling files with nonstandard characters in them? 

Thank you for you time,

Severin
-- 
They that can give up essential liberty to obtain a little temporary safety 
deserve neither liberty nor safety.
Benjamin Franklin
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] UnicodeDecodeError when copying files with Umlauten

2005-07-10 Thread Severin Kacianka
Hello, 

I finally could solve the problem on my own. These two articles helped me a 
lot:
http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/
http://www.reportlab.com/i18n/python_unicode_tutorial.html

I simply had to ensure that all the file names I got from the m3u file were in 
unicode format. I do that by simply running "unicode" over every filename I 
extract from the m3u files:
self.pathList.append(unicode(eachLine[:-1],"latin-1"))

Severin
-- 
They that can give up essential liberty to obtain a little temporary safety 
deserve neither liberty nor safety.
Benjamin Franklin
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor