Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Section 1.1: false statement about the REPL #67

Closed
ghost opened this issue Jun 20, 2020 · 4 comments
Closed

Section 1.1: false statement about the REPL #67

ghost opened this issue Jun 20, 2020 · 4 comments

Comments

@ghost
Copy link

ghost commented Jun 20, 2020

Warning: It is never possible to paste more than one Python command (statements that appear after >>>) to the basic Python shell at a time. You have to paste each command one at a time.

This is false, at least on FreeBSD with xfce4-terminal. I've been using Python for 6 years and can't remember this ever being true.

@dabeaz
Copy link
Contributor

dabeaz commented Jun 20, 2020

The >>> prompt is not valid Python. You can't just take the output of an interactive session as shown and paste it at the prompt. Sorry.

>>> import urllib.request
>>> >>> u = urllib.request.urlopen('http://ctabustracker.com/bustime/map/getStopPredictions.jsp?stop=14791&route=22')
  File "<stdin>", line 1
    >>> u = urllib.request.urlopen('http://ctabustracker.com/bustime/map/getStopPredictions.jsp?stop=14791&route=22')
     ^
SyntaxError: invalid syntax
>>> >>> from xml.etree.ElementTree import parse
  File "<stdin>", line 1
    >>> from xml.etree.ElementTree import parse
     ^
SyntaxError: invalid syntax
>>> >>> doc = parse(u)
  File "<stdin>", line 1
    >>> doc = parse(u)
     ^
SyntaxError: invalid syntax
>>> >>> for pt in doc.findall('.//pt'):
  File "<stdin>", line 1
    >>> for pt in doc.findall('.//pt'):
     ^
SyntaxError: invalid syntax
>>>         print(pt.text)
  File "<stdin>", line 1
    print(pt.text)
    ^
IndentationError: unexpected indent
>>> 

@dabeaz dabeaz closed this as completed Jun 20, 2020
@ghost
Copy link
Author

ghost commented Jun 20, 2020

Sorry, I guess I misunderstood the statement. I interpreted it as meaning you couldn't paste multiple commands into the prompt at once, rather than that you couldn't paste them including the >>>. I would recommend clarifying the wording (it's not the pasting of the multiple commands at once that's invalid, but the inclusion of the >>>, regardless of how many lines you include).

@dabeaz
Copy link
Contributor

dabeaz commented Jun 20, 2020

Pasting multiple commands (even without the >>>) also fails in environments such as IDLE.

@dabeaz
Copy link
Contributor

dabeaz commented Jun 20, 2020

Example (from IDLE), pasting two print statements on separate lines.

Python 3.8.1 (default, Jan  8 2020, 16:15:59) 
[Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> print("hello")
print("world")
SyntaxError: multiple statements found while compiling a single statement
>>> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant