我想在我的計算機(Windows 7)的給定路徑中創建一個文件,但該文件未在給定路徑中創建。它直到時間碼被執行時纔在編譯器中創建,但它不會在OS上創建。獲取在Windows操作系統中寫入文件的權限
x = str(input("Please enter the file name: "))
x = 'C:\Users\Aakash\Documents\Aakash\Aakash College\Practical\MIT Paython\\'+x
f = open('x','w')
print 'Please choose your option:'
print '1.Write'
print '2.Read'
choice = int(input('Enter the number: '))
while choice==1:
text = input('Please enter the string: ')
f.write(text)
f.write('\n')
print 'Please choose your option:'
print '1.Write'
print '2.Read'
choice = int(input('Enter the number: '))
if choice==2:
f.close()
print
f = open('x','r')
text = f.readline()
print text
while text!='':
text = f.readline()
print text
f.close()
我認爲windows沒有授予創建文件的權限。那麼如何獲得這個權限,以便在給定的位置創建一個真實的文件?
它工作,而我嘗試與IDLE相同的一段代碼,但是當我嘗試它在一個新的文件(通過創建模塊)它不起作用! (即模塊運行正常,沒有任何錯誤但不會創建真實文件)
注意:該文件是從管理員用戶帳戶運行的。他有權訪問所有的目錄。
你如何創建和運行模塊? – Blender
您正試圖打開一個名爲'x'的文件。 – Matthias
嘗試'f = open(x,'w')' – martineau