variables exist
Brian van den Broek
bvande at po-box.mcgill.ca
Tue Apr 12 12:33:40 EDT 2005
Richard Brodie said unto the world upon 2005-04-12 04:56:
> "Brian van den Broek" <bvande at po-box.mcgill.ca> wrote in message
> news:mailman.1703.1113237192.1799.python-list at python.org...
>
>
>>I'm a hobbyist and still learning, but the claim the try/except is
>>"lousy Python" surprise me a bit.
>
>
> I think it wasn't the use of try/except as such. It's more that
> if you're the developer you ought to know whether variables
> are defined or not. It might be a sign you're using global
> variables more often than would be considered good style in
> Python.
Richard and STeVe,
thanks for the replies :-)
I see your point, Richard. Though where it has come up for me most
often is code internal to a class, where I only need a "real" value
for a class attribute in some cases, depending upon the inputs to the
class __init__. "Globals are bad" is one lesson I have learned :-)
STeVe stressed that the try/except solution is only really appropriate
for cases where the failure to have the variable defined is quite
rare. Even though wary of "the root of all evil ... " that seems a
good reminder. Thanks.
Best to all,
Brian vdB
More information about the Python-list
mailing list