在windows中用os,path.abspath(__file__)时有中文路径时,默认是转成非unicode格式

这会导致,在其它模块使用该路径时,会报

  utf8' codec can't decode byte 0xb7 in position 14: invalid start byte

 

怎么处理呢?

网上百度了一把,解决方法都不妥当,还是来个非通用的吧,但很好使用:

如下

project_path = os.path.abspath(__file__.decode('gbk'))

用该方法简单便捷

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2021-12-10
  • 2021-12-10
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案