with (open(os.path.join(curpath, unique_name)), 'w') as fw:
出现以下错误(为了清晰起见,对公司详细信息进行了模糊处理) :
Traceback (most recent call last):
File "./crap.py", line 60, in uniquify
with (open(os.path.join(curpath, unique_name)), 'w') as fw:
IOError: [Errno 2] No such file or directory: '/<mypath>/bin/python/<filename>'
这些括号将“ w”与 with ()函数放在一起,而不是像预期的那样与 open ()放在一起。我很惊讶它会出现这个 IO 错误,这意味着 open ()调用出了问题,这使得追踪这个错误比追踪显然来自 with ()调用要困难得多。
我不相信这些结果,只是再次修改它来复制,是的,我得到了同样的错误。
当我将括号切换到正确的版本时:
with (open(os.path.join(curpath, unique_name), 'w')) as fw: