![](/img/trans.png)
[英]How to load a text or csv file which is in a different parallele directory using a python script when i do not have access to absolute path
[英]How can I access a file in a completely different directory based on absolute path (Python)
import os
test = os.path.exists("c:/conf.txt")
if test == False:
with open("c:/conf.txt", "w") as Inc:
Inc.write("0")
Inc.close()
quit()
if test == True:
f = open("c:/conf.txt", 'r')
b = int(f.readline())
b +=1
with open("c:/conf.txt", 'w') as writeinc:
writeinc.write(str(b))
writeinc.close()
使用open(c:/conf.txt)
不起作用(也嘗試了c:\\。)
我收到以下錯誤消息:
IOError: [Errno 22] invalid mode ('w') or filename: 'c:/conf.txt'
有沒有一種方法可以使用open()
根據絕對路徑而不是相對路徑來訪問其他目錄?
在我看來,您無權寫入驅動器的根路徑。 在Windows 7和8中,不能在根目錄中創建文件:
在Windows 7或8(可能是Vista)中,不允許用戶(甚至管理員)在C驅動器根目錄中創建文件,否則,將出現錯誤消息,例如“客戶端未保留必需的特權”或“拒絕”的提示。
如果您要解決此限制,本文將繼續介紹如何修改注冊表。
- 按“ Windows鍵+ R”鍵,鍵入regedit
- 找到HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Policies \\ System \\ EnableLUA
- 將EnableLUA值更新為0(如果關閉,則將其關閉)
- 重新啟動Windows。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.