简体   繁体   中英

Python - utf-8 coding issue

My code is:

path = "d:\\path\\"
dirs = os.listdir(path)
print u'Files:'
for i in dirs:
    if i[-3:] == 'xls':
        print i

file = raw_input('File: ')
workbook = xlrd.open_workbook(file)

My filesnames contains letters as "ąń". workbook = xlrd.open_workbook(file) can't use file from raw_input. Filename is for example "mondayń.xls". I get error: No such file or directory: 'monday\\xe4.xls'. print i command gives proper filenames. How can I solve it? I am sorry for my english...

PS I use python 2.7.10 and Win10

The files are in D:\\\\path , but you're only printing the file names, then opening the name they type. You need to join the name to the path, eg with fullpath = os.path.join(path, file) , then open that.

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