您的位置:首页 > 编程语言 > Python开发

Python3与Python2中print的用法改变与Class获取属性学习

2013-01-12 12:00 471 查看
Reference: http://planet.python.org/python2中 print 'hello world'python3中 print ('hello world')获取属性的方法使用__dict__
import inspect

class Test:
        """"""
        #--------------------------------------------
        def __init__(self):
                self.varOne = ""
                self.varTwo = ""
                self.varThree = ""

        #--------------------------------------------
        def methodOne(self):
                """"""
        #       print "You just called methodOne!"
                print ("You just called methodOne!")

#----------------------------------------------------
if __name__ == "__main__":
        t = Test()
        variables = [i for i in t.__dict__ if not inspect.ismethod(i)]
        print (variables)
        print ('End of File')
以下两种方法也可以,并且第二种不需要import inspect.
variables = [i for i in t.__dict__ if not callable(i)]
variables = t.__dict__.keys()

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: