设为首页 加入收藏

TOP

Python实现支持JSON存储和解析的对象(二)
2015-02-02 14:37:56 来源: 作者: 【 】 浏览:20
Tags:Python 实现 支持 JSON 存储 解析 对象
? ? numpy matrix.call this function after newobject = objectLoadFromFile(jsonfile)'''?
? ? ? ? ? ? pass?
?
? ? p = Person('Aidan',22)? ? ? ?
? ? #json.dumps(p)#error will be throwed?
? ? ?
? ? #objectDumps2File(p,'Person.json')?
? ? p.jsonDumps()?
? ? p_l = objectLoadFromFile('p.json')?
? ? ? ?
? ? print 'the decoded obj type: %s, obj:%s' % (type(p_l),repr(p_l))?


Python类有新旧两种,py 2.2 后类定义继承 object 的目的是使这个类成为 new style class, 没有继承 object 的为传统classic class(最终也会继承object)。


类定义中如下两种方法:


class Person():?
class Person(object)?


其区别在于:


若创建新的Person instanc test,则type(test)的输出分别为:


?
?


inspect 模块提供了一系列自省函数,它可以获取模块,类,方法,函数,traceback,帧对象,代码对象的信息。常用的方法getmembers,ismodule,getcallargs,isclass等,更多详细信息参见http://docs.python.org/library/inspect.html。


--------------------------------------分割线 --------------------------------------


--------------------------------------分割线 --------------------------------------


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言符号优先级 下一篇Python多线程之线程创建和终止

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: