0

Im pretty new to Python (2.7) and no programming experience before. Anyway Im in the process of learning python but have a mysterious error that I can't figure out. Whenever I put equal sign in print statement, I get syntax error.

here's an example code

def main():
    f = open('lines.txt')
    for line in f:
        print(line, end = '')

if __name__ == "__main__": main()

really simple but it was just for a line break so I i ignore "end = ''" (actually figured out by using comma^^) but as I learn more, the problem is getting bigger and bigger.

please anyone knows what is the problem? I assume that it could be Python version issue (Im using 2.7) but not really sure. If it is which version of Python should I use? btw I really like .format function tho

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Delu:sional
0

For that function you use pyhton 3.x, or you do:

from __future__ import print_function

def main():
    f = open('lines.txt')
    for line in f:
        print(line, end = '')

if __name__ == "__main__": main()

Cheers and Happy coding

Edited by Beat_Slayer: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.