[英]Create a file with the same name as a directory in Python
我有一個目錄/project/my_name/
我需要創建一個文件/project/my_name
但是:
with open(filename, 'w') as outfile:
outfile.write(my_content)
IOError: [Errno 21] Is a directory: u'/project/my_name'
有什么幫助嗎?
從文件系統的角度來看,目錄是一種文件。 您不能有兩個名稱相同的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.