python
  • windows
  • file
  • 2012-12-20 83 views -2 likes 
    -2

    我想在我的計算機(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相同的一段代碼,但是當我嘗試它在一個新的文件(通過創建模塊)它不起作用! (即模塊運行正常,沒有任何錯誤但不會創建真實文件)

    注意:該文件是從管理員用戶帳戶運行的。他有權訪問所有的目錄。

    +0

    你如何創建和運行模塊? – Blender

    +1

    您正試圖打開一個名爲'x'的文件。 – Matthias

    +0

    嘗試'f = open(x,'w')' – martineau

    回答

    0

    運行的用戶該代碼必須具有對當前目錄的寫入權限。

    +0

    該代碼是從管理員的帳戶和他作爲訪問所有目錄運行。 (特別是上面給出的目錄),但仍然沒有創建。 – Aakash

    相關問題