I’m trying to read a file line by line. This file has alot of lines.
Each line is formatted like for example:
data:otherdata1
data:someotherdata2
But for debug purposes I’m using a file with a few lines, same format.
And I’m trying to print those data.
But I’m getting the error:
print data.split(':')
^
SyntaxError: invalid syntax
What is wrong? I’m really lost in this.
def process(data):
print data.split(':') #printing for debug purposes
return data
file = open("list.txt")
for line in file:
process(line)
and yes I added import fileinput
You are using Python3 with Python2 syntax.
In Python3,
printis a function, not a statement. So useinstead.