Need to determine whether the variable has been defined. This is an easy task in PHP. You can just use the isset function to determine the variables, but it doesn't seem to be that simple in Python. I googled it, but there were no good results, so I finally had to write one myself. This is done using try .. except ..else.
Imitates PHP and defines an isset function.
def isset(v):
try:
type (eval(v))
except:
return 0
else:
return 1
def isset(v):
try:
type (eval(v)) except:
return 0
else:
🎜>
When determining whether a variable is defined, just call this function directly, but it should be noted that a string must be passed in. For example, when determining whether user_name is defined, you need to call
like this·········10········20·········30········ 40·········50·········60·········70········80·········90···· ····100·······110·······120·······130·······140·······15001.if isset( user_name ):
print user_name is defined
else
print user_name is not defined
http://www.bkjia.com/PHPjc/486102.html
www.bkjia.com
true