这段代码的语法有什么问题?

时间:2017-04-11 20:30:54

标签: python python-3.x

with open('list.txt') as f:
    print " ".join(line.strip() for line in f)

Though the code seems to be correct, but facing syntax error !

2 个答案:

答案 0 :(得分:1)

在python 3中,print是一个函数。见这里:https://docs.python.org/3/whatsnew/3.0.html#print-is-a-function

尝试:

with open('list.txt') as f:
    print(" ".join(line.strip() for line in f))

答案 1 :(得分:0)

您正在使用python版本3,使用此

   with open('line.txt') as f:
   print(" ".join(line.strip() for line in f))