python open 文件名过长解决方法
有如下代码
file = "...."
with open(file, 'r', encoding="UTF-8") as content_file: try: content = content_file.read() except Exception as e: print(e)
file的路径非常长,超过260个字符,引起错误:
No such directory or file.
在https://docs.python.org/3/using/windows.html#removing-the-max-path-limitation
这里看到非常好的解决方案。
Your administrator will need to activate the “Enable Win32 long paths” group policy, or set LongPathsEnabled
to 1
in the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
.
regedit修改注册表,解决了问题。
比加"\\?\"等方案好。