Python Forum
proper use of 'end' in a 'with' statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
proper use of 'end' in a 'with' statement
#1
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.
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Correct/proper way to create save files snakes 0 435 Mar-11-2025, 06:58 PM
Last Post: snakes
  Pyserial issues with proper loops and binary jttolleson 16 5,567 Nov-02-2023, 08:39 PM
Last Post: deanhystad
  Getting proper x,y axis values pyhill00 8 3,697 Jul-29-2022, 06:48 PM
Last Post: pyhill00
  Proper way to do the OR statement? Mark17 5 2,783 Mar-01-2022, 01:54 PM
Last Post: Mark17
  Proper use of if..elif..else statement nick1941 2 3,055 Mar-06-2020, 11:22 PM
Last Post: nick1941
  Proper Layout of Code Question TheJax 2 2,811 Feb-08-2020, 06:14 PM
Last Post: TheJax
  Unable to do the proper split using re.sub incase of missing data. Karz 1 2,388 Nov-17-2019, 05:58 PM
Last Post: buran
  getopt with tuple not working proper Frank123456 0 2,305 Aug-21-2019, 12:46 PM
Last Post: Frank123456
  proper syntax for itertuples? ilcaa72 1 2,495 Jun-06-2019, 02:41 AM
Last Post: scidam
  Need help excluding Named Entity (NE) and proper nouns (NNE) from text analysis disruptfwd8 0 2,756 May-15-2018, 12:10 AM
Last Post: disruptfwd8

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020