Parentheses (as after "print")
Peter Otten
__peter__ at web.de
Wed Sep 27 03:25:54 EDT 2017
Stefan Ram wrote:
> Why do we newbies write »print 2«? Here's another hint.
> This is an original transcript of what happened to me today:
>
> |>>> import( operator )
> | File "<stdin>", line 1
> | import( operator )
> | ^
> |SyntaxError: invalid syntax
> |
> |>>> import operator
> |
> |>>> help operator
> | File "<stdin>", line 1
> | help operator
> | ^
> |SyntaxError: invalid syntax
> |
> |>>> help( operator )
> |Help on module operator:
>
> What happened? I woke up today in parens mood. So I typed:
>
> import( operator )
>
> Python told me that I should type:
>
> import operator
>
> . Fine, Python conditioned me to omit the parens.
> So now I was in noparens mood. So I typed:
>
> help operator
>
> . Oops!
>
> "Don't make me think!"
If you want that level of -- let's call it consistency -- you should either
plead for
foo = import("foo")
to spell an import or expect
print foo
to be syntactic sugar for
foo = __print__("foo")
(As for the ":" -- easy to read wins over easy to type.)
More information about the Python-list
mailing list