Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91632

Re: A simple print cannot run in Python Shell

From Jussi Piitulainen <jpiitula@ling.helsinki.fi>
Newsgroups comp.lang.python
Subject Re: A simple print cannot run in Python Shell
Date 2015-06-01 10:59 +0300
Organization A noiseless patient Spider
Message-ID <lf5382bq2ou.fsf@ling.helsinki.fi> (permalink)
References <caa1cc9e-2f9b-423d-9298-a511180d15f7@googlegroups.com>

Show all headers | View raw


fl writes:

> When I run the following command in a Python 2.7.9 Shell on Windows 7,
>
> print r'C:\\nowhere'
>
> It has error:
>
>>>> print r'C:\\nowhere'
> SyntaxError: invalid syntax
>
> What is the problem? Why does it behave different at .py file
> and Python Shell?

Have you executed the following in that shell?

   from __future__ import print_function

That replaces the Python 2 print command with the Python 3 print
function and then you would get that error message.

Apologies if you've done that because I used it in one of my examples
about reversed(). I didn't mean to confuse - I've just never quite
learnt the Python 2 print syntax myself.

There is no "from __past__ import print_command", is there? To recover
the original functionality in that shell :)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

A simple print cannot run in Python Shell fl <rxjwg98@gmail.com> - 2015-06-01 00:50 -0700
  Re: A simple print cannot run in Python Shell Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2015-06-01 10:59 +0300
  Re: A simple print cannot run in Python Shell Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-01 18:30 +1000
    Re: A simple print cannot run in Python Shell Tim Golden <mail@timgolden.me.uk> - 2015-06-01 09:46 +0100

csiph-web