assignment in control structure syntax (was Re: Curious assignment behaviour)

Mike Ryan miker at 21stcenturyhealth.com
Thu Oct 11 14:29:54 EDT 2001


"Dale Strickland-Clark" <dale at riverhall.NOSPAMco.uk> wrote in message
news:qtqast8mifvlmhpv3ft9die9ma211op90o at 4ax.com...
> Chris Dutton <chris at cmb-enterprises.com> wrote:
> >The example I saw somewhere that I liked was
> >
> >if something as x:
> >   do_something_to(x)
>
> Presumably, 'something as x' assigns to x and yields x?
>
> It doesn't seem at all obvious to me. I had to think about it for a
> while before figuring it out. Also, having an assignment working to
> the right is very counter-intuitive.

Actually, it's not all that different from  the "import ... as ..." syntax
of the statement:

    import spam as bacon
    dir(bacon)

--

Michael Ryan
Information Services Manager
21st Century Health and Benefits, Inc.




More information about the Python-list mailing list