problem with special characters in filename
muralimkrishan26 at yahoo.com
Fri Jan 23 10:46:59 CET 2009
file1 = open('a.dat','r') #opens file for reading
for line in file1:
## old_name = line[0:len(line)-1] #gets rid of "\n" suffix
## print old_name
line.strip() #gets rid of "\n" suffix
os.rename('b.dat',line) #renames file
From: "fizzotti at gmail.com" <fizzotti at gmail.com>
To: python-list at python.org
Sent: Friday, January 23, 2009 2:43:24 PM
Subject: problem with special characters in filename
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
I have two files (let's assume they are all in the same directory):
1) "a.dat" containing the single line "Sébastien.dat"
2) "Sébastien.dat" containing arbitraty data
I want to:
read in the single line ("Sébastien.dat")
copy the file described by the single line ("Sébastien.dat") to
another location with name "b.dat"
This is what I have started with:
file = open('a.dat','r') #opens file for reading
for line in file:
old_name = line[0:len(line)-1] #gets rid of "\n" suffix
shutil.copy(old_name, 'b.dat') #copies file
However I get the following error:
IOError: [Errno 2] No such file or directory: 'S\xc3\xa9bastien.dat'
I'm sure this has something to do with encoding and decoding UTF-8 and
Unicode or something like that, but everything I've tried has yet to
produce any favourable results.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list