<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Try this:<br><br>import shutil,os<br><br>file1 = open('a.dat','r') #opens file for reading<br>for line in file1:<br>    print line<br>##    old_name = line[0:len(line)-1] #gets rid of "\n" suffix<br>##    print old_name<br>    line.strip() #gets rid of "\n" suffix<br>    print line<br>os.rename('b.dat',line) #renames file<br>file1.close()<br><br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 13px;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> "fizzotti@gmail.com" <fizzotti@gmail.com><br><b><span style="font-weight: bold;">To:</span></b>
 python-list@python.org<br><b><span style="font-weight: bold;">Sent:</span></b> Friday, January 23, 2009 2:43:24 PM<br><b><span style="font-weight: bold;">Subject:</span></b> problem with special characters in filename<br></font><br>
using:<br><br>Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)<br>[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2<br><br><br>Hello<br><br>I have two files (let's assume they are all in the same directory):<br><br>1) "a.dat" containing the single line "Sébastien.dat"<br>2) "Sébastien..dat" containing arbitraty data<br><br>I want to:<br><br>open "a.dat"<br>read in the single line ("Sébastien.dat")<br>copy the file described by the single line ("Sébastien.dat") to<br>another location with name "b.dat"<br><br>This is what I have started with:<br><br>import shutil<br><br>file = open('a.dat','r') #opens file for reading<br>for line in file:<br>    print line<br>    old_name = line[0:len(line)-1] #gets rid of "\n" suffix<br>    print old_name<br>shutil.copy(old_name, 'b.dat') #copies file<br><br>However I get the following error:<br>IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat'<br><br>I'm sure this has
 something to do with encoding and decoding UTF-8 and<br>Unicode or something like that, but everything I've tried has yet to<br>produce any favourable results.<br><br>Thanks<br>Dino<br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></div></div></div><br>



      </body></html>