python语法错误常见原因_python3中open()的语法错误,不知道原因
已解決
我正在寫(xiě)一本《艱難地學(xué)習(xí)Python》一書(shū),當(dāng)我試圖打開(kāi)這個(gè)文件的時(shí)候,我總是遇到一個(gè)語(yǔ)法錯(cuò)誤,我可能只是做了一些愚蠢的事情,錯(cuò)過(guò)了一些顯而易見(jiàn)的東西,但我無(wú)法理解。非常感謝你的幫助。在from sys import argv
script, input_file = argv
def print_all(f):
print(f.read())
def rewind(f):
print(f.seek(0))
def print_a_line(line_count, f):
print(line_count, f.readline()
current_file = open("input_file")
print("First let's print the whole file: \n")
print_all(current_file)
print("Now let's rewind, kind of like a tape")
rewind(current_file)
print("Finally, let's print three lines:")
current_line = 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
current_line = current_line + 1
print_a_line(current_line, current_file)
當(dāng)我試圖聲明變量current_file并將其分配給open(“input_file”)時(shí),出現(xiàn)錯(cuò)誤。謝謝。在
總結(jié)
以上是生活随笔為你收集整理的python语法错误常见原因_python3中open()的语法错误,不知道原因的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: tp5 excel 导入 mysql_T
- 下一篇: mysql双机数据热备份_如何设置MyS