Larry Bates wrote:
> 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 l_init really is a boolean parameter and l_value a value that _might_ exist in a shelve. So I just want to have a parameter to a method so if the first value tested is false (l_init) then the second (l_value) does not get tested ... because it is the second in the statement and only seems to get evaluated if the first one is true. Philippe -- http://mail.python.org/mailman/listinfo/python-list