
Hi, I have a query in using function names. Python allows users to write their own functions with built-in function names. Example: def print(): return "strange" print() -- Returns strange ++++++++++++++++++++++++++++ But the built in "print" function doesn't work any more till i restart the shell. I personally feel users should not be allowed to use built in function names. Is there any special reason why python allows them? Thanks, David Becker

And of course the same thing happens if we use them for variable names as well.
type = 2 type(4) Traceback (most recent call last): File "<pyshell#74>", line 1, in <module> type(4) TypeError: 'int' object is not callable
I feel there is no point in allowing them as they cannot be used. Users are restricted to use the 32 keywords but we can't force them to remember all built in function names and not to use them as variable or function names. :) Thanks, David Becker On Sat, Feb 6, 2016 at 11:11 AM, david becker <ardavidbecker@gmail.com> wrote:
Hi,
I have a query in using function names. Python allows users to write their own functions with built-in function names.
Example: def print(): return "strange"
print() -- Returns strange ++++++++++++++++++++++++++++
But the built in "print" function doesn't work any more till i restart the shell. I personally feel users should not be allowed to use built in function names. Is there any special reason why python allows them?
Thanks, David Becker

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi David, there are few reasons why this is the way it is: - - The builtins are not the only names that can be accidentally overridden. The same goes for imported modules, or any classes/functions imported from modules. It's hard to see where to draw the line. - - At the same time, being able to override existing name bindings is part of the Pythonic "consenting adults" policy. It makes it possible, for example, to quickly change how output using "print" works in a script. - - The interactive shell is a special case anyway. Normally the shadowing is limited to the module or local scope where it happens. Note that as with many other questions of freedom vs enforcement, linters like pyflakes/pylint do a good job of recoginizing this shadowing and warning about it if so desired. cheers, Georg On 02/06/2016 06:49 AM, david becker wrote:
And of course the same thing happens if we use them for variable names as well.
type = 2 type(4) Traceback (most recent call last): File "<pyshell#74>", line 1, in <module> type(4) TypeError: 'int' object is not callable
I feel there is no point in allowing them as they cannot be used. Users are restricted to use the 32 keywords but we can't force them to remember all built in function names and not to use them as variable or function names. :)
Thanks, David Becker
On Sat, Feb 6, 2016 at 11:11 AM, david becker <ardavidbecker@gmail.com <mailto:ardavidbecker@gmail.com>> wrote:
Hi,
I have a query in using function names. Python allows users to write their own functions with built-in function names.
Example: def print(): return "strange"
print() -- Returns strange ++++++++++++++++++++++++++++
But the built in "print" function doesn't work any more till i restart the shell. I personally feel users should not be allowed to use built in function names. Is there any special reason why python allows them?
Thanks, David Becker
_______________________________________________ docs mailing list docs@python.org https://mail.python.org/mailman/listinfo/docs
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAla3H7oACgkQN9GcIYhpnLABqACfaPpaYIBEkVBxFL71PXhHJlKO WKMAn0WJ3BrTSe3ogv4uaevp6HkHarjj =KV53 -----END PGP SIGNATURE-----
participants (2)
-
david becker
-
Georg Brandl