os.path.join()斜杠与反斜杠

  • Post author:
  • Post category:其他


问题:

directory1='/user/hou/Package'
directory2='python'
directory3=os.path.join(directory1,directory2)
print('directory3 : %s' %directory3)

结果:


directory3 : /user/hou/Package\python


没有拼接成功…

解决:

directory1='/user/hou/Package/'
directory2='python'
directory3=os.path.join(directory1,directory2)
print('directory3 : %s' %directory3)

只需在Package后加一个斜杠,即可拼接起来!

结果:


directory3 : /user/hou/Package/python



版权声明:本文为hb_learing原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。