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

Recommended Answers

All 2 Replies

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

Thanks Beat_Slayer!
you saved my day

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.