Python获取%appdata%路径的方法
import os
import sys
import winreg
print(os.name)
print(sys.getdefaultencoding())
print(sys.version)
print(sys.version_info)
def get_desktop():
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders')
return winreg.QueryValueEx(key, "Desktop")[0]
print(get_desktop())
# 其他的类似,如:LOCALAPPDATA
appdata = os.getenv("APPDATA")
print(appdata)
或者是:
env = os.environ
appdata = env['APPDATA']
print(appdata)
sys.exit()
pyinstaller --onefile deletelog.py 将脚本生成一个EXE文件