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 



上一篇:php时间差计算,计算1天后1小时后时间
下一篇:PHP扩展高性能日志系统SeasLog

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