我在編寫代碼,需要在文本文件中輸入2個數字,然後將它們分開,並將答案顯示爲最重要的部分。當我在程序中輸入我自己的值時,我得到了分數部分,但我無法讓程序識別文本文件。我曾嘗試將它們放在同一目錄中,並放置文件的完整系統路徑,但目前爲止還沒有發揮作用。現在我只是想要打印文件的內容。'invalid argument'error and python not reading file
with open('C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 3.4\topheavy.txt','w') as f:
for line in f:
for word in line.split():
print(word)
那麼我就要分配2個值x和y,但我得到這個錯誤:
Traceback (most recent call last):
File "C:\Python34\divider.py", line 2, in <module>
open('C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 3.4\topheavy.txt','w')
OSError: [Errno 22] Invalid argument:'C:\\ProgramData\\Microsoft\\Windows\\Startmenu\\Programs\\Python 3.4\topheavy.txt'
感謝您的幫助。
感謝,雙\\對我的作品。 – 2018-01-01 16:36:10