open() and Arabic language

M

MaaSTaaR

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 ?
 
S

Simon Forman

MaaSTaaR said:
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
 
B

Butternut Squash

MaaSTaaR said:
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.
 
J

John Machin

MaaSTaaR said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top