Python Forum

Full Version: proper use of 'end' in a 'with' statement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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