On Mon, Mar 17, 2008 at 3:37 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:
>  ...
>  Can you give another rule that you prefer and that I can comprehend and
>  that I can explain to Python newcomers?  The OP only gave a few examples of
>  * usage and (initially) no rule that I saw.

Really, it is as clear as is the summer sun.   Maybe we should add it
to the tutorial to be clear:

'*':  Python expansion operator expands things to bigger things.  For
example, "3*5" expands 3 by multiplying by five while "3**5" expands
it twice resulting in exponentiation.  In exactly the same vein
'import * from mod" expands the implicit namespace by the symboles in
mod, unless mod has __all__ in which case by not all the symbols.  *a
expands a into a tuple, or into a the current tuple if inside a
function parameter list, so **a expands it twice, except at the end
where **a means it is a dictionary of names not used yet.  Which fits
well with the use of expanding in general expressions where *a,b,c =
expr expands a into a tuple to be big enough to hold the expression.
Be careful not to use **a,b,c = expr as this causes a to expand to far
and blow up the compiler.   Similarly the the * can be used on the
left hand side to expand things there.  * can't be used by itself as
you can't blow up nothing, and should be avoided on Sparc machines
because blowing up the sun is a nonrecoverable boo-boo.  See also
"diving where the is tuple while avoiding a really bad tan."  Some
code might make this clear.

import * from animals;
rabbits = rabbits * rabbits ** rabbits  # they breed fast and will
double expand before the single expand.
mice = *mouse.blind()*3 # poor mice in a tuple
*cat = *mice  # blind mice which is three mouses get eaten by a cat,
of which there is only one.
dog1, *dog2 = cat, *cat, *mice  # which is a concise way of saying if
two dogs eat the cat and the cat has mice, then
# the second dog eats not only the cat and the mice but any other
blind mice around.
count(first_dog=dog1, *dog2)
# how many mice are in the second dog is left as an exercise in philosophy.
# unfortunately, this really isn't very Pythonic because dogs are not
snakes, as everyone knows.


Seriously, this proposed syntax is about as clear as silly proposals
for "def foo(self, a,b,lamda c:self.d())"
creating an array of code to magically execute in a created context.
It's a useful special case, just not special enough.

Have a fun day!
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to