[英]Syntax error when trying to open a file through Python 3 Command Shell
您必須使用括號()
而不是<>
file = open("example.txt","r")
檢查https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
幾個問題:
1.您的文本文件被稱為“example.txt.txt”而不是“example.txt”
2.“example.txt”、“r”應該用括號()而不是<>括起來。 這些符號在 cmd 中看起來很相似,很容易混淆。
#instead of
file = open<"example.txt","r">
#use
file = open("example.txt","r")
這應該可以解決您的問題; 讓我知道是否有。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.