proper use of 'end' in a 'with' statement - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: proper use of 'end' in a 'with' statement (/thread-25089.html) |
proper use of 'end' in a 'with' statement - ccrider27 - Mar-18-2020 Python newbie here. Code snippet: >>> with open('todos.txt') as tasks: for chore in tasks: print(chore, end=' ')SyntaxError: invalid syntax ??? I copied this straight out a text book. If I remove the ", end=' '" from the print command at the end, it runs fine. I have tried "end=''" - removing the space between the tics, still get syntax error. I have tried using double quotes, still get syntax error I tried help('with'), but there is no mention of the end statement. Maybe 'end' has been deprecated? Any help is appreciated. Note: The code suite is properly indented in my code, but the 'thread editor' removes them when I submit?? Should have mentioned: I'm using Python 3.7, and the textbook was copyrighted 2017. RE: proper use of 'end' in a 'with' statement - buran - Mar-18-2020 lines 2 and 3 need to be indented one level compared to line 1 OP claims indentation is correct end is param to print() function, not to with context manager
|