我希望使用 Python 创建并编写一个位于隐藏文件夹中的 .txt 文件。我正在使用以下代码:
file_name="hi.txt"
temp_path = '~/.myfolder/docs/' + file_name
file = open(temp_path, 'w')
file.write('editing the file')
file.close()
print 'Execution completed.'
其中~/.myfolder/docs/是一个隐藏文件夹。我遇到了以下错误:
Traceback (most recent call last):
File "test.py", line 3, in <module>
file = open(temp_path, 'w')
IOError: [Errno 2] No such file or directory: '~/.myfolder/docs/hi.txt'
当我将文件保存在一些非隐藏的文件夹中时,相同的代码可以工作。
有什么想法为什么对于隐藏的文件夹,open()不起作用。