Is this a legal / acceptable statement ?
Larry Bates
larry.bates at websafe.com
Fri May 5 10:25:57 EDT 2006
Philippe Martin wrote:
> Hi,
>
> This code works, but is it "appropriate" ?
>
> l_init = False
>
> if True == l_init and 1234 = l_value:
> print 'l_value is initialized'
>
> I know I can do this with a try but ...
>
> Philippe
>
>
1) You have a syntax error 1234 == l_value (note ==)
2) This doesn't test to see if l_value is initialized
because if it isn't you get:
Traceback (most recent call last):
File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "junk.py", line 1, in ?
if True == l_init and 1234 == l_value:
NameError: name 'l_init' is not defined
3) It is unclear what l_init is used for in this context.
Setting it to True doesn't tell you anything about l_value.
Normally you do something like:
l_value=None
.
. Intervening code
.
if l_value is None:
print "l_value uninitialized"
Or (something I never use):
if not locals().has_key('l_value'):
print "l_value uninitialized"
-Larry Bates
More information about the Python-list
mailing list