2012-01-16 4 views
1

の最大数ので、私はTwitterのAPIを呼び出しています:まあ、 異なるオブジェクトがに裁断されTwitterのAPIパイソン - オブジェクト

[{"entities":{"hashtags":[],"user_mentions":[],"urls":[{"url":"http:\/\/t.co\/Hd1ubDVX","indices":[115,135],"display_url":"amzn.to\/tPSKgf","expanded_url":"http:\/\/amzn.to\/tPSKgf"}]},"coordinates":null,"truncated":false,"place":null,"geo":null,"in_reply_to_user_id":null,"retweet_count":2,"favorited":false,"in_reply_to_status_id_str":null,"user":{"contributors_enabled":false,"lang":"en","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/151701304\/theme14.gif","favourites_count":0,"profile_text_color":"333333","protected":false,"location":"North America","is_translator":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/151701304\/theme14.gif","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1642783876\/idB005XNC8Z4_normal.png","name":"User Interface Books","profile_link_color":"009999","url":"http:\/\/twitter.com\/ReleasedBooks\/genres","utc_offset":-28800,"description":"All new user interface and graphic design book releases posted on their publication day","listed_count":11,"profile_background_color":"131516","statuses_count":1189,"following":false,"profile_background_tile":true,"followers_count":732,"profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1642783876\/idB005XNC8Z4_normal.png","default_profile":false,"geo_enabled":false,"created_at":"Mon Sep 20 21:28:15 +0000 2010","profile_sidebar_fill_color":"efefef","show_all_inline_media":false,"follow_request_sent":false,"notifications":false,"friends_count":1,"profile_sidebar_border_color":"eeeeee","screen_name":"User","id_str":"193056806","verified":false,"id":193056806,"default_profile_image":false,"profile_use_background_image":true,"time_zone":"Pacific Time (US & Canada)"},"possibly_sensitive":false,"in_reply_to_screen_name":null,"created_at":"Thu Nov 17 00:01:45 +0000 2011","in_reply_to_user_id_str":null,"retweeted":false,"source":"\u003Ca href=\"http:\/\/twitter.com\/ReleasedBooks\/genres\" rel=\"nofollow\"\u003EBook Releases\u003C\/a\u003E","id_str":"136957158075011072","in_reply_to_status_id":null,"id":136957158075011072,"contributors":null,"text":"Digital Media: Technological and Social Challenges of the Interactive World - by William Aspray - Scarecrow Press. http:\/\/t.co\/Hd1ubDVX"},{"entities":{"hashtags":[],"user_mentions":[],"urls":[{"url":"http:\/\/t.co\/GMCzTija","indices":[119,139],"display_u 

openurl = urllib.urlopen("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&contributor_details&include_rts=true&screen_name="+user+"&count=3600") 

をし、それは次のようにいくつかの長いファイルを返します。テーブルや辞書を使用していますが、私はさまざまな部分を抽出したいと思いますが、これを行うにはファイルのオブジェクト数を知る必要があります。

例:

[{1:info , 2:info}][{1:info , 2:info}][{1:info , 2:info}][{1:info , 2:info}] 

ので、私は希望最初のテーブルに1から情報を抽出する:

[0]['1'] 
>>>>info 

しかし、私は、テーブルが持っているどのように多くのオブジェクトを知る必要があり、テーブル内の最後のオブジェクトからそれを抽出すること。だから、どのように私は、この表の最後のオブジェクトの値を見つけるのですか

table_timeline = json.loads(twitter_timeline) 

    table_timeline_inner = table_timeline[x] 
    lines = 0 
    while lines < linesmax: 
     in_reply_to_user_id = table_timeline_inner['in_reply_to_status_id_str'] 
     lines += 1 

これは私のコードは次のようになりますか?

おかげ

答えて

1

は、私は、これはあなたが探しているもので、完全にわからないんだけど、-1のインデックスを使用して、Pythonのリストの最後の項目を取得します。たとえば、

>>> alist = [{'position': 'first'}, {'position': 'second'}, {'position': 'third'}] 
>>> print alist[-1]['position'] 
{'position': 'third'} 
>>> print alist[-1]['position'] 
third