Testing conditions.

Ray Gibbon ray at rgibbon.freeserve.co.uk
Thu Feb 10 00:38:54 EST 2005


Testing conditions.

Common scenario.  Old programmer, new to Python, love it, but still
hankering after some of my old ways.

Of all of it's 'new to me' features, I appear to be enjoying 'no
declarations' and mixing types with abandon.  In particular I find myself
writing functions which return whatever might be useful in whatever type
seems appropriate, I'm really attracted to this, it works like magic.

BUT, every time the result of a fuction hits a 'while' or 'if' the magic
stops.  If I want the result and I want to test it I have to do an
assignment and test separately.  It grates every time I come across this,
and it seems obvious what I'm hankering for.

I *know* this has been gone over and over and over...
This is NOT another request for statements to be accepted as expressions for
two reasons:-
1. I've seen enough arguments on the subject where I've found myself firmly
on the anti change side.
2. I now realise that it might scratch the itch, but it would not cure it.

e.g. 1
|    while new_data = get_more_data(source):
|        process_data(new_data)

is obviously the sort of thing I'm missing, but it is not a general solution
because :-

e.g. 2
|    while new_data, environment = get_more_data(source):
|        process_data(new_data, environment)

is something I'm equally likely to want to do, but I can't express it's
meaning.

Before I resign myself to the inevitable, 'that's the way it is - get used
to it', I'd just like to scratch it once.  But, before I try walking on very
thin ice, I want to ask whether there are expectations of some future
changes which address these issues?

I note PEP 3000 is silent on this matter, and PEP 315, though related, is
not relevant.

Ray.





More information about the Python-list mailing list