Opinion on best practice...

Chris Angelico rosuav at gmail.com
Fri Feb 8 07:54:39 CET 2013

On Fri, Feb 8, 2013 at 9:49 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Chris Angelico wrote:
> Yes, that is correct. Because now you are executing code, which could do
> something, and some things are dangerous. But Python will never execute
> code unless you explicitly tell it to. There's no concept in Python of
> falling back onto code execution if parsing fails.

A bare expression IS explicitly calling for code execution. That's
simply the way the language is. If you don't want the return value to
be sent to the host, you either assign it to a variable, or use CALL
(if it's a function call).

> I note that you ignored my question. If REXX reaches code that fails to
> parse, does it send it to the shell to be executed by default? If the
> answer was No, I expect you would have said so.

Anything that doesn't parse is a syntax error. It's only expression
results that go to the host (shell).

> Good lord, that's even worse than I feared. So it's not just unparsable
> non-REXX code that is implicitly sent to the shell, but the equivalent to
> Python's NameErrors. And you can implicitly mix calls to the shell and REXX
> function calls in the same line.

If it was meant to be a name, then it'll be in an expression, which -
see above - is an explicit request for it to be handled by the host.
The only thing that'll trip you up there is misspelling a language

iff blah blah blah blah

which will be sent to the host instead of being an 'IF' statement.


More information about the Python-list mailing list