Opinion on best practice...
rosuav at gmail.com
Thu Feb 7 08:49:49 CET 2013
On Thu, Feb 7, 2013 at 5:50 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Thu, 07 Feb 2013 16:28:17 +1100, Chris Angelico wrote:
>> You misunderstand. It's actually a very simple rule. Python follows C's
>> principle of accepting that any return value from an expression should
>> be ignored if you don't do anything with it.
> Return values are safe. They don't do anything, since they are *being
> ignored*, not being executed as code. You have to explicitly choose to do
> something with the return value before it does anything.
> If C said "if you don't do anything with the return result of an
> expression, execute it as code in the shell", would you consider that a
> desirable principle to follow?
> def oh_my_stars_and_garters():
> return "rm -rf /"
Naming a function is safe, too.
os.system("rm -rf /")
But putting parentheses after it suddenly makes it dangerous. Wow!
Python's pretty risky, right?
In REXX, you simply don't *do* that sort of thing. (You'd use the CALL
statement, for instance.)
More information about the Python-list