- 论坛徽章:
- 0
|
- # -*- coding:utf-8 -*-
- import os
- import urllib
- def printfile(dir):
- files = [f for f in os.listdir(dir)
- if os.path.isfile(os.path.join(dir , f))]
- for file in files:
- name = unicode(file)
- print name.encode('utf-8')
- dire = [d for d in os.listdir(dir)
- if os.path.isdir(os.path.join(dir , d))]
- for x in dire:
- #y = dir + "\\" + x
- printfile(os.path.join(dir, x))
- printfile('e:/book')
复制代码
- PerlCookBook.chm
- The_Perl_Programming_Language_en.pdf
- Traceback (most recent call last):
- File "d:\MyProject\python\MyPython\listDir.py", line 19, in <module>
- printfile('e:/book')
- File "d:\MyProject\python\MyPython\listDir.py", line 10, in printfile
- name = unicode(file)
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xa9 in position 3: ordinal not in range(128)
复制代码
看错误信息应该是没有按照utf-8来处理 为什么呢 呵呵 |
|