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


Messages In This Thread
proper use of 'end' in a 'with' statement - by ccrider27 - Mar-18-2020, 09:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyserial issues with proper loops and binary jttolleson 16 2,628 Nov-02-2023, 08:39 PM
Last Post: deanhystad
  Getting proper x,y axis values pyhill00 8 1,686 Jul-29-2022, 06:48 PM
Last Post: pyhill00
  Proper way to do the OR statement? Mark17 5 1,778 Mar-01-2022, 01:54 PM
Last Post: Mark17
  Proper use of if..elif..else statement nick1941 2 2,429 Mar-06-2020, 11:22 PM
Last Post: nick1941
  Proper Layout of Code Question TheJax 2 2,212 Feb-08-2020, 06:14 PM
Last Post: TheJax
  Unable to do the proper split using re.sub incase of missing data. Karz 1 1,874 Nov-17-2019, 05:58 PM
Last Post: buran
  getopt with tuple not working proper Frank123456 0 1,889 Aug-21-2019, 12:46 PM
Last Post: Frank123456
  proper syntax for itertuples? ilcaa72 1 2,011 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,351 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