One - One Code All

Blog Content

python中检测某个变量是否有定义

Python   2014-12-27 21:50:44

1.内置函数locals():


    'testvar'   in   locals().keys()


2.使用内置函数dir():


    'testvar'   in   dir()


3.使用内置函数vars():


    vars().has_key('testvar')


4.try except方法:



def isset(v): 

   try : 

     type (eval(v)) 

   except : 

     return  0 

   else : 

     return  1 



上一篇:pandas.DataFrame.fillna前向填充pad与后向填充bfill
下一篇:python遍历目录,拼接域名

The minute you think of giving up, think of the reason why you held on so long.