- 论坛徽章:
- 0
|
新手继续求教,这段东西我弄了好几天了,小问题不断ORZ,python好严谨,有点累- import os
- import shutil
- appdata_path = os.getenv("APPDATA")
- print (appdata_path)
- prefs_path=appdata_path+r'\Mozilla\Firefox\Profiles\vysoaq03.aurora\prefs.js'
- print (prefs_path)
- shutil.copy2('prefs_path','prefs.js')
- file = open('prefs.js', encoding='utf-8')
- a_string = file.read()
- sStr = 'user_pref("general.useragent.locale", "zh-CN");'
- a_string = a_string.replace(sStr, 'user_pref("general.useragent.locale", "en");')
- testFile = open('prefs.js','w', encoding='utf-8')
- testFile.write(a_string)
- testFile.close()
复制代码 运行结果:
C:\Users\cking\AppData\Roaming
C:\Users\cking\AppData\Roaming\Mozilla\Firefox\Profiles\vysoaq03.aurora\prefs.js
Traceback (most recent call last):
File "H:\个人文件夹\Python\案例\1111111111.py", line 9, in <module>
shutil.copy2('prefs_path','prefs.js')
File "F:\编程\python3\lib\shutil.py", line 144, in copy2
copyfile(src, dst)
File "F:\编程\python3\lib\shutil.py", line 98, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 'prefs_path'
我感觉,是因为prefs_path虽然是正确的地址,然是使用的是\,会使地址转义,但是prefs_path是个变量名,变量可以直接使用r咩?貌似我试了程序还是出错。 |
|