By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

open() and Arabic language

P: n/a
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 ?

Aug 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 ?
On this page http://www.amk.ca/python/howto/unicode , there is a brief
section near the bottom on "Unicode filenames". If your problem is
related to Unicode, this may help you, but I'm not sure.

HTH,
~Simon

Aug 13 '06 #2

P: n/a
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 ?
probably a unicode problem. Good luck.
Aug 13 '06 #3

P: n/a
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 AM 17 ??.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

Aug 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.