This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Function print definable as variables?
Type: behavior Stage: resolved
Components: Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, ozy, r.david.murray
Priority: normal Keywords:

Created on 2014-01-15 00:40 by ozy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg208125 - (view) Author: Ozy (ozy) Date: 2014-01-15 00:40
Not sure if this is a bug. We're experiencing it in v3.3.2 and was discovered by accident.

It seems to be possible to define python functions (like print or input) as variables, as if they're not reserved. If you do that, the command functionality is lost until Python is reseted.

For example try this in IDLE:

>>> print = 10
>>> print
10
>>> print(print)
TypeError: int object is not callable
>>> print(10)
TypeError: int object is not callable

Here is a screenshot >

http://imgur.com/IpjELhp

We tested it, and this doesn't happen in v2.

Sorry if this has been reported previously.

Best regards.
msg208126 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-15 00:46
Yes, that's the way Python works.  In Python3, print became a function and is no longer a keyword, so yes, it can be shadowed in the local namespace just like any other Python function.
msg208127 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2014-01-15 00:53
FTR you can always get it back from builtins.print:

>>> print('test')
test
>>> print = 10
>>> print('test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> import builtins
>>> print = builtins.print
>>> print('test')
test
msg208128 - (view) Author: Ozy (ozy) Date: 2014-01-15 01:08
Great, thanks. Didn't know that.

All the best.
History
Date User Action Args
2022-04-11 14:57:56adminsetgithub: 64462
2014-01-15 01:08:01ozysetmessages: + msg208128
2014-01-15 00:53:20ezio.melottisetnosy: + ezio.melotti
messages: + msg208127
2014-01-15 00:46:15r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg208126

resolution: not a bug
stage: resolved
2014-01-15 00:40:07ozycreate