objectifier使检查和遍历python对象变得容易。

objectifier的Python项目详细描述


对象化符图片::https://secure.travis-ci.org/aurorasoftware/objectifier.png?branch=master
:target:https://travis ci.org/aurorasoftware/objectifier


objectifier是一个使遍历字典、列表和其他
python对象更加容易的工具。

如果您有要报告的错误或功能请求,请将其添加到我们的"问题跟踪程序"中
<;https:。//github.com/aurorasoftware/objectifier/issues>;`.

…_安装:

installation
----


objectifier位于"pypi"上。您可以通过"pip"或"easy"安装,
根据您的喜好进行安装。::

$pip安装objectifier

…_ PIP:http://www.pip-installer.org/en/latest/
。_ pypi:http://pypi.python.org

…_配置:

usage
----


objectifier接受任何python对象(字符串、字典、列表、元组、
等),并将其转换为具有一些非常酷的属性的对象。

假设您正在与twitter api交互,并且有一个json tweet,您希望操作它或遍历它。_ json tweet:javascript:toggletweet();

…原始::html

<;脚本类型='text/javascript'>;
$(function(){
$.getjson("https://api.twitter.com/1/statuses/show.json?id=112652479837110273&include_entities=true&callback=?",函数(json){
$("pre tweet").html(json.stringify(json,null,4));
};
});

函数toggletweet(){
if(tweethidden){
tweethidden=false;
$("pre tweet").fadein();
}
其他{
tweethidden=true;
$("pre tweet").fadeout();
}
}
<;/script>;
<;div class='highlight-js'>;<;div class='highlight'>;<;pre id='tweet'style='display:none'>;<;/pre>;<;/div>;<;/div>;



在使用``json`
模块将响应解析为python字典之后,我们可以这样显示列表中所有用户提到的内容。用法:

>;>tweet=json.loads(response.read())
>;","。join(tweet中用户的"screen\u name"]tweet中用户的"entities"]["user\u inspections"])

主要的区别是您可以使用点表示法访问属性。:

>>gt;tweet=objectifier(response.read())
>>gt;","。join(tweet.entities.user中用户的user.screen名称。user提到)


`objectifier`类将包装任何python字符串、unicode字符串、
字典、列表或元组。如果输入是json字符串,objectifier将在将其保留为文本之前尝试对其进行解析。这允许您执行上述操作,而无需对响应
数据使用"json.load"。



>>tweet中的"user"
true


,并获取定义"len"的对象中的项数。:

>;>len(tweet.entities.user_u references)
3


上面的东西很好,但不是游戏改变者。objectifier的真正力量
在python控制台中熠熠生辉。用法:

>;>tweet
<;objectifier\dict user=dict favorited=bool entities=dict contributors=nonetype truncated=bool text=unicode created=unicode retweetd=bool in_reply_status_id_str=nonetype coordinates=nonetype in_reply_user_id_str=unicode source=unicode in_reply_to_status_id=nonetype in_reply_to_screen_name=unicode id_str=unicode place=nonetype retweet_count=int geo=nonetype id=int possible_sensitive=bool in_reply_id=int>;

原始对象获得了漂亮显示的所有好处。例如::

>;>>tweet.user
<;objectifier dict follow request sent=nonetype profile use background image=bool default profile image=bool id=int verified=bool profile image url https=unicode profile边栏fint=int profile_sidebar_border_color=unicode id_str=unicode profile_background_color=unicode listed_count=int profile_background_url_https=unicode utc_offset=nonetype status_count=int description=unicode friends_count=int location=unicode profile_link_color=unicode profile_image=unicodefollowing=nonetype show_all_inline_media=bool geo_enabled=bool profile_background_image_url=unicode screen_name=unicode lang=unicode profile_background_tile=bool favorites_count=int name=unicode notifications=nonetype url=unicode created_at=unicode contributors_enabled=bool time_zone=nonetype protected=bool default_profile=bool is_translator=bool>;
>;>tweet.user.profile_image_url
u'http://a0.twimg.com/profile_images/1380912173/screen_shot_2011-06-03_at_7.35.36_pm_normal.png'

如果您检查列表,objectifier将告诉您元素的数量。:

>;>;tweet.entities.user悻提到
<;objectifier悻list elements:3>;



>;>;tweet。<;tab>;
…贡献者…id…在用户的回复中…source
…坐标…id…str…如果需要的话客观化…文本
…创建于…在"回复到"屏幕上的名称…位置…被截断
…实体…在"回复到"状态下的ID…可能是敏感的…用户
…受欢迎…在"回复到"状态下的ID str…转发计数
…地理位置…在回复用户ID时…转发了

——

*github:https://github.com/aurora software/objectifier
*电子邮件:opensource@aurora.io
*twitter:`@aurora_software<;http://twitter.com/aurora_software>;。`_

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何用java表示这个数学函数的算法   Java/Stream帮助:仅使用streams将嵌套的映射列表转换为映射   使用Selenium连接到数据库时发生java未知主机异常   java如何了解jvm内存使用:“堆内存”和“堆外内存”   java Oracle BI报告导入模板   java如何使用Spring将xml转换为bean?   java线程。join()以保证执行顺序   java从THINGSPEAK到ANDROID应用程序获取JSON数据   使用Java的stanford库中的异常   java正确使用来自其他类文件的方法   如果集合中的元素类型为接口类型,如何填充集合?(爪哇)   记录java。util。记录器创建的文件超过了应有的数量   类Java对象uniq值   尝试调用无法应用于()的方法时出现java错误