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)

 

相关文章:

  • 2021-10-26
  • 2021-10-29
  • 2021-08-19
  • 2021-11-20
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-26
  • 2021-07-27
  • 2022-12-23
  • 2021-09-15
相关资源
相似解决方案