Python for循环语法错误

Python for循环语法错误,python,centos,Python,Centos,for循环中似乎有语法错误,但我不知道为什么。我对Python有些陌生,我正在Centos中尝试这一点 fil = open('acnt_data_text.txt', 'r') for data_str in fil: result = subprocess.call(["php", "class.php"], data_str) print result fil.close() 语法错误:无效语法:对于fil:中的数据,您应该在另一行的冒号(result=subprocess.

for循环中似乎有语法错误,但我不知道为什么。我对Python有些陌生,我正在Centos中尝试这一点

fil = open('acnt_data_text.txt', 'r')
for data_str in fil:
    result = subprocess.call(["php", "class.php"], data_str)

print result

fil.close()

语法错误:
无效语法:对于fil:

中的数据,您应该在另一行的冒号(
result=subprocess.call等…
)后面添加内容,以便更容易阅读。另外,这可能会修复语法错误。

我认为它应该像这样隔开

fil = open('acnt_data_text.txt', 'r')
for data_str in fil: 
   result = subprocess.call(["php", "class.php"], data_str)
print result

fil.close()
如果将
一起使用,则可以避免关闭文件

with open('acnt_data_text.txt', 'r') as fil:
    for data_str in fil: 
       result = subprocess.call(["php", "class.php"], data_str)
    print result

确保代码中的这一行
result=subprocess.call([“php”,“class.php”],data\u str)
在for循环中。