Python from Wise Guy's Viewpoint

Alex Martelli aleax at aleax.it
Mon Oct 20 15:49:41 EDT 2003


David Eppstein wrote:

> In article <mailman.262.1066668221.2192.python-list at python.org>,
>  Gerrit Holl <gerrit at nl.linux.org> wrote:
> 
>> > I fail to see the lack of uniformity. "print" and "del" are statements,
>> 
>> I think it is not uniform that print and del are statements rather than
>> functions, since they don't do control flow (just like exec). In all
>> three cases, I don't see why it is a statement.
> 
> It's not obvious how to write e.g. del a[x] as a function, since the

Well, it IS obvious how to write it as a method -- a.__delitem__(x) ...:-).

As a function, it would be operator.delitem(a, x) [this IS in fact quite
an acceptable spelling today, as long as you 'import operator' first].


On the other hand,

   del localname

is tougher.  A function delete_local('localname') would be just too
black-magical (having functions affect their caller's locals, BRRRR).

> argument is an lvalue (position x of list a) rather than an rvalue (the
> item in position x of list a).

Yeah, but in a container you can represent the lvalue with the pair
(container, index), as a variable you might (but for the distaste of
black magic) represent it as a string.


> Exec needs to be executed in the current scope, not the scope of another
> function call.

That's only exec with implicit scope (a VERY dubious usage indeed).

And the main reason to have it a statement (was a function in some
early Python) is so the compiler can avoid ANY local-name optimization
in functions containing such an abomin^H^H^H^H dubious usage.

> Print, I agree, is something of a wart, but a useful one.

Yeah, well, so-so.  A built-in function would be just as useful
(you could represent "no line-end" or "to file xxx" with optional
keyword arguments, rather than with the quirky trailing comma
and the yecchy "print>>xxx, ..." abom^H^H^H^H quaint usage).


There's a snowball's chance in hell that even Python 3.0 will
drop any of these, of course, but I do believe Python would be
an even better language WITHOUT "exec in implicit scope", without
print as a statement, and (perhaps) without a 'del' statement
(delattr is already a built-in function, making delitem one too
would be fine, and global variables could easily be dealt with
through my old idea of an "import __current_module__" followed
by a delitem; local variables are the ONLY real issue here).


Alex





More information about the Python-list mailing list