Python, are you ill?

W

wxPythoner

If you are in the interactive prompt of the Python interpreter and you
do this

print """Testing\""" or print '''Testing\'''

you get three dots [...] as if Python expects a code block. If you
press Enter, you get three dots again, and again, and again... You
can't get out of the code block with pressing the Enter key; you have
to press Ctrl+Z (if you're in Linux) in order to get out of that code
block, which then throws you back to the Linux command line, but
before that it prints this line

[1]+ Stopped python


If you do

print "Testing\" or print 'Testing\'

you get an error, but not of you use the triple quotes. Is that a bug
in the interpreter perhaps?
 
J

John Machin

If you are in the interactive prompt of the Python interpreter and you
do this

print """Testing\""" or print '''Testing\'''

you get three dots [...] as if Python expects a code block. If you
press Enter, you get three dots again, and again, and again... You
can't get out of the code block with pressing the Enter key; you have
to press Ctrl+Z (if you're in Linux) in order to get out of that code
block, which then throws you back to the Linux command line, but
before that it prints this line

[1]+ Stopped python

If you do

print "Testing\" or print 'Testing\'

you get an error, but not of you use the triple quotes. Is that a bug
in the interpreter perhaps?

No. This might clue you in:

Cheers,
John
 
J

John Henderson

If you are in the interactive prompt of the Python interpreter
and you do this

print """Testing\""" or print '''Testing\'''

you get three dots [...] as if Python expects a code block. If
you press Enter, you get three dots again, and again, and
again... You can't get out of the code block with pressing the
Enter key; you have to press Ctrl+Z (if you're in Linux) in
order to get out of that code block, which then throws you
back to the Linux command line, but before that it prints this
line

[1]+ Stopped python


If you do

print "Testing\" or print 'Testing\'

you get an error, but not of you use the triple quotes. Is
that a bug in the interpreter perhaps?
"""
testing"""

John
 
N

Nicolas Dandrimont

If you are in the interactive prompt of the Python interpreter and you
do this

print """Testing\""" or print '''Testing\'''

you get three dots [...] as if Python expects a code block. If you
press Enter, you get three dots again, and again, and again... You
can't get out of the code block with pressing the Enter key;

That is because Python expects you to end the triple-quoted string with
three unescaped quotes.
you have to press Ctrl+Z (if you're in Linux) in order to get out of that code
block, which then throws you back to the Linux command line, but
before that it prints this line

[1]+ Stopped python

That ^Z just suspends your Python interpreter. It has become a job you can
now bring to foreground again with "fg". (but it's a feature of your
shell, not of Python)
If you do

print "Testing\" or print 'Testing\'

you get an error, but not of you use the triple quotes. Is that a bug
in the interpreter perhaps?

The fact is, that triple-quoted strings can span on multiple lines, and
that single-quoted strings cannot (without the line ending with a "\").
So no, it's not a bug in the interpreter.

Regards,
--
Nicolas Dandrimont


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIJg/macIxuZqlam0RAhTMAJkBGeZbbBtec9fKN7ER4Gm4ClwrzACfS8dp
CMznjDm86kX45J9QE9GRYWg=
=80Hp
-----END PGP SIGNATURE-----
 
M

Matt Nordhoff

You
can't get out of the code block with pressing the Enter key; you have
to press Ctrl+Z (if you're in Linux) in order to get out of that code
block, which then throws you back to the Linux command line, but
before that it prints this line

[1]+ Stopped python

You can use Ctrl+C and Python will stop what it's doing and go back to
its main prompt.
--
 
T

Tim Roberts

If you are in the interactive prompt of the Python interpreter and you
do this

print """Testing\""" or print '''Testing\'''

you get three dots [...] as if Python expects a code block.

....which it does.
If you
press Enter, you get three dots again, and again, and again... You
can't get out of the code block with pressing the Enter key; you have
to press Ctrl+Z (if you're in Linux) in order to get out of that code
block,

No, you don't. You can also enter """ or ''' to properly close the quote.
If you do

print "Testing\" or print 'Testing\'

you get an error, but not of you use the triple quotes. Is that a bug
in the interpreter perhaps?

As a general rule, when you are just beginning to learn some product, it is
safe to assume that anything you see as a bug in the product is almost
certainly a flaw in your understanding of the product.
 
C

castironpi

If you are in the interactive prompt of the Python interpreter and you
do this
print """Testing\"""   or   print '''Testing\'''
you get three dots [...] as if Python expects a code block.

...which it does.
If you
press Enter, you get three dots again, and again, and again... You
can't get out of the code block with pressing the Enter key; you have
to press Ctrl+Z (if you're in Linux) in order to get out of that code
block,

No, you don't.  You can also enter """ or ''' to properly close the quote.
If you do
print "Testing\"   or   print 'Testing\'
you get an error, but not of you use the triple quotes. Is that a bug
in the interpreter perhaps?

As a general rule, when you are just beginning to learn some product, it is
safe to assume that anything you see as a bug in the product is almost
certainly a flaw in your understanding of the product.

I hold further, it is more profitable, unless you can change it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top