Python Forum
Why doesn't this work in the Python Shell?
Thread Rating:
  • 3 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why doesn't this work in the Python Shell?
#11
(Oct-26-2016, 06:23 AM)diemildefreude Wrote:
(Oct-26-2016, 03:44 AM)Larz60+ Wrote: the 2nd print statement will simply print a end of line.
since the loop is not doing this, the effect is to finish the line of the loop,
not and extra line.

if you change it to print some text you will see this (at the end of the loop print on same line)

Ah, I think I see the problem. the last print is not related to the loop, so it's processed as an error if you enter it in the ... at the end of the loop statement. But in a script, it's perceived as a new statement.

this seems to be the case, not specific to print

Output:
lt1/forums /home/forums 12> py2 Python 2.7.12 (default, Jul  1 2016, 15:12:24) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> i = 1 >>> while i <= 6: ...     i += 1 ... x = i   File "<stdin>", line 3     x = i     ^ SyntaxError: invalid syntax >>> lt1/forums /home/forums 13> py3 Python 3.5.2 (default, Sep 10 2016, 08:21:44) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> i = 1 >>> while i <= 6: ...     i += 1 ... x = i   File "<stdin>", line 3     x = i     ^ SyntaxError: invalid syntax >>> lt1/forums /home/forums 14>
Doh
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help creating shell scrip for python file marciokoko 10 1,256 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 870 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Launch Python IDLE Shell from terminal Pavel_47 5 1,143 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,681 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 842 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 1,655 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 4,052 May-30-2022, 03:31 PM
Last Post: bowlofred
  batch file for running python scipt in Windows shell MaartenRo 2 1,825 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 1,930 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,657 Oct-30-2021, 11:20 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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