【python】os.getcwd和getcwdu

print os.getcwd(), type(os.getcwd())
print os.getcwdu(), type(os.getcwdu())

结果如下:

C:\Users\Administrator\PycharmProjects\mypython_1 <type 'str'>
C:\Users\Administrator\PycharmProjects\mypython_1 <type 'unicode'>

 

可见,一个是返回str,一个是返回unicode

看下面的代码:

s = os.getcwd()
s+= '\测试1'
os.mkdir(s)

运行正常,但是创建的目录是乱码

 

要得到正确的结果,应该这样:

u = os.getcwdu()
u+= u'\测试2'
os.mkdir(u)

 

posted @ 2016-02-01 10:49  房子斯特  阅读(667)  评论(0编辑  收藏  举报