+ 4
How we can do this in python?
I have a python code.it contain many variables.and I want to find variable name, it means if python code contain this variable which I want to find it,than it will run otherwise not run.and how i can find the variable present or not present in my Python code.How I can do that in python.
4 Respostas
+ 4
# to find all the local variables
if 'var' in locals().keys():
print 'yes'
# to find all the global variables
if 'var' in globals().keys():
print 'yes'
+ 5
I have a idea.
try:
print(x)
except NameError:
print('Variable is not found')
+ 4
Maninder Singh yeah nice!
+ 3
Self help is the best help!