简体   繁体   中英

Python opening a hebrew path to file and using glob with hebrew

I have a root dir in hebrew and a file name in hebrew. I wish to do the following:

fullPath = os.path.join(dirName, fileName)
f = file(fullPath)

and also I wish to find all the excel files that starts with a hebrew prefix:

excelPath= os.path.join(dirName, "%s*.xlsx" % hebrewPrefix)
for fn in glob.glob(excelPath):
            print fn

How can I achieve that?

It works as expected on Japanese (assuming I have the folder こんにちは containing the file 世界.xls ):

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> fullpath = os.path.join("こんにちは","世界.*")
>>> import glob
>>> for fn in glob.glob(fullpath):
...     print fn
... 
こんにちは/世界.xls

You shouldn't have any difficulties in Hebrew. The only problem would be if your filesystem does not support UTF-8 for file names...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM