Michael J. Fromberger wrote:
> Would the following be a satisfactory implementation?
>
> def isset(varname, lloc = locals()):
> return varname in lloc or varname in globals()
>
> I believe this works as desired:
>
> >>> x = 5
> >>> def f(y):
> ... z = 10
> ... print isset('z')
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (fabian) wrote:
> how testing if a variable exists in python as isset in php??
>
Would the following be a satisfactory implementation?
def isset(varname, lloc = locals()):
return varname in lloc or varname in globals()
I believe this wor
Scott David Daniels wrote:
Brian van den Broek wrote:
... STeVe stressed that the try/except solution is only really
appropriate for cases where the failure to have the variable defined
is quite rare.
Beware: C++ and Java have an immense overhead for exceptions. Python
has a very lightweight ex
Scott David Daniels wrote:
> >... STeVe stressed that the try/except solution is only really
appropriate
> > for cases where the failure to have the variable defined is quite rare.
>
> Beware: C++ and Java have an immense overhead for exceptions. Python
> has a very lightweight exception mechanis
Brian van den Broek wrote:
... STeVe stressed that the try/except solution is only really appropriate
for cases where the failure to have the variable defined is quite rare.
Beware: C++ and Java have an immense overhead for exceptions. Python
has a very lightweight exception mechanism. You shou
Richard Brodie said unto the world upon 2005-04-12 04:56:
"Brian van den Broek" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
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 mo
"Brian van den Broek" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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 whe
Brian van den Broek wrote:
Fredrik Lundh said unto the world upon 2005-04-11 10:14:
"fabian" wrote:
how testing if a variable exists in python as isset in php??
try:
variable
except NameError:
print "variable not set"
but that is really lousy Python; better make sure you always assign to
al
Fredrik Lundh said unto the world upon 2005-04-11 10:14:
"fabian" wrote:
how testing if a variable exists in python as isset in php??
try:
variable
except NameError:
print "variable not set"
but that is really lousy Python; better make sure you always assign to
all variables, and use None
try:
myVariable
except NameError:
print "Not bound"
else:
print "Bound"
If you want to distinguish between the local an the global environment:
if globals().has_key( "myVariable" ):
...
versus
if locals().has_key( ".
HTH,
Gerald
fabian schrieb:
how testing if a variable exists in python as
"fabian" wrote:
> how testing if a variable exists in python as isset in php??
try:
variable
except NameError:
print "variable not set"
but that is really lousy Python; better make sure you always assign to
all variables, and use None (or another suitable value) to mark that some
variabl
how testing if a variable exists in python as isset in php??
thanks
--
http://mail.python.org/mailman/listinfo/python-list
12 matches
Mail list logo