文件过滤_Python 3.2
我正在尝试用 Python 编写一个简短的文件过滤代码来找到我想要的字符串。
我已经按逻辑解决了这个问题,但是我的命令源向我发送了有关 print 语句的错误消息。这就是它现在的工作方式:
filename = input('give file name: ')
n = input('give desired string: ')
f = open
line = f.readline()
while line:
if n in line:
print line
line = f.readline()
错误声明:
Traceback (most recent call last):
File "<string>", line 7, in <fragment>
Syntax Error: print line: <string>, line 718
我知道这是一个简单的问题,但答案对我来说并不明显。请帮忙。
I'm trying to write a short file filtering code in Python that will find my desired string.
I've got it worked out logically, but my Command Feed is sending me an error message for the print statement. This is how it works as of now:
filename = input('give file name: ')
n = input('give desired string: ')
f = open
line = f.readline()
while line:
if n in line:
print line
line = f.readline()
Error Statement:
Traceback (most recent call last):
File "<string>", line 7, in <fragment>
Syntax Error: print line: <string>, line 718
I know this is a simple problem but the answer is not obvious to me. please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
print
是 Python 3 中的一个函数。请使用print(line)
代替。print
is a function in Python 3. Useprint(line)
instead.