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()
相关文章推荐
- assert 用法及获取IP 分类: python基础学习 2013-07-24 16:54 344人阅读 评论(0) 收藏
- 对比Python中__getattr__和 __getattribute__获取属性的用法
- Python学习:获取标签属性
- 原生js获取元素的class属性(获取class的所有元素)以及改变或添加calssName
- Python学习笔记——print语句用法总结
- python学习之----获取标签属性
- 初学Python的学习笔记9----面向对象编程(获取对象信息、实例属性和类属性)、面向对象高级编程(使用__slots__、使用@property)
- 对比Python中__getattr__和 __getattribute__获取属性的用法
- Python 学习笔记 - 10.类(Class) 1
- python学习之 字符串前'r'的用法
- ES6 类(Class)基本用法和静态属性+方法详解
- python中获取异常描述与else用法
- jQuery基础学习(3)(获取标签属性,动态添加标签)
- Python学习笔记五(面向对象-类-方法-属性)
- Python学习之类属性
- Python print函数用法,print 格式化输出
- python Property属性用法
- Python学习——Numpy的tile函数用法
- python中类的学习:类属性,实例属性 __new__方法:单例模式
- Python 学习系列(2)and、or用法