Tôi muốn tạo và viết tệp .txt trong một thư mục ẩn bằng cách sử dụng python. Tôi đang sử dụng mã này:open() không hoạt động đối với các tệp bị ẩn python
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.'
nơi ~/.myfolder/docs/là một thư mục ẩn. Tôi nhận được lỗi:
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'
Cùng một mã hoạt động khi tôi lưu tệp vào một số thư mục không ẩn.
Bất kỳ ý tưởng nào tại sao open() không hoạt động đối với các thư mục ẩn.
Bạn đang sử dụng hệ điều hành nào? – enginefree
http://stackoverflow.com/questions/13215716/ioerror-errno-13-permission-denied-when-trying-to-open-hidden-file-in-w-mod – John
Tôi đang sử dụng ubuntu – user2460869