selenium报错信息-- Python 中 'unicodeescape' codec can't decode bytes in position XXX: trun错误解决方案

本以为是缺少utf-8造成的错误,但是加完这个还是报错,于是在网上百度了一下是因为上传的路劲粗无偶导致的selenium报错信息-- Python 中 'unicodeescape' codec can't decode bytes in position XXX: trun错误解决方案

正确的写法是把路劲中“\”变为“\\”,或者在路劲的开头加上“r”,或者在路劲的开头加上“r”并且把“\”变为“/”

如下:

1、os.system('C:\\Users\\fyr\\Desktop\\auit.exe')

2、os.system(r'C:\Users\fyr\Desktop\auit.exe')

3、os.system(r'C:/Users/fyr/Desktop/auit.exe')

具体原因:

window读取文件可以用"\",但是在字符串中“\”是被当作转义字符来使用。

解决办法:

Python中描述路劲时可以有多种方式,以下是常见的三种:

   1、转义的方式

'd:\\a.txt'
2、显式声明字符串不用转义 'd:r\a.txt' 3、使用Linux的路径 'd:/a.txt'
在linux和window下都可以用第三种

相关文章:

  • 2021-05-12
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-12-11
  • 2021-08-10
猜你喜欢
  • 2021-12-30
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
相关资源
相似解决方案