MaaSTaaR wrote:
> Hello ...
>
> firstly , sorry for my bad English .
>
> i have problem with open() function when i use it with file which name
> in Arabic , the open() will not find the file , and i am sure the file
> is exist .
>
>
> so how i can solve this problem ?
Provide more information -- a major factor is which operating system
[my crystal ball says that you are using Linux but it could be wrong].
Also an actual test case with a short file name. Here's an example with
a part-Chinese filename on a Windows machine, which just uses the
information in the Unicode HOWTO that you were pointed at by another
poster:
C:\junk\unicode_name>dir
[snip]
30/05/2006 09:25 AM17 ??.txt
[snip]
# only 1 file in the directory; dir command mangles the displayed name
C:\junk\unicode_name>python
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
|>>> import os
|>>> os.listdir('.')
['??.txt']
|>>> os.listdir(u'.')
[u'\u5f20\u654f.txt']
# filename is kept in Unicode, so we can open it that way
|>>> f = open(u'\u5f20\u654f.txt')
|>>> f.read()
'yadda yadda yadda'
# success
|>>> import sys
|>>> sys.getfilesystemencoding()
'mbcs'
... I'm guessing that you will find that you have to encode the
filename in utf-8 then feed it to the open() function.
If you still have a problem, come back with exact (copy/paste) results
of both os.listdir() [the '.' and the u'.'], the
sys.getfilesystemencoding(), and your failed open() attempt.
Hope this helps,
John
--
http://mail.python.org/mailman/listinfo/python-list