Py学习  »  Python

os.path.exist 检测中文路径是否存在

techchina • 11 年前 • 10303 次点击  

Python的os.path.exists判断中文路径时,给以gbk(或gb2312)编码,才能找到,否则为False.

例如:

#-*-coding:utf-8-*-

a=r"d:\测试.txt"

b=r"d:\abc123.txt"
c=a.encode('gbk')
d=e.encode('gbk')

import os
print(os.path.exists(a))

>>>False
print(os.path.existss(b))
>>>True
print(os.path.exists(c))
>>>True
print(os.path.exists(d))
>>>True
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/442
 
10303 次点击  
文章 [ 1 ]  |  最新文章 11 年前
Py站长
Reply   •   1 楼
Py站长    11 年前

赞~