2010-06-03 3 views
0

저는 주어진 달에 얼마나 많은 블로그 항목이 게시되었는지 간단히 알려주는 간단한 Python 스크립트를 작성하기 위해 노력하고 있습니다. pyblog 앱은 매우 유용합니다.알 수없는 특정 Python 객체 속성을 호출하는 방법은 무엇입니까?

그러나 블로그 개체를 만들 때 다양한 속성에 액세스하는 방법을 모르겠습니다. 아래 (발췌)와 같이 나는 사전에서 하나 개의 항목을 인쇄하여 그들을 모두 밖으로 인쇄 할 수 있습니다 :

print blog.get_recent_posts(1) 

[{'mt_keywords': 'Storage in 2010, Storage, Twitter', 'permaLink': 'http://itknowledgeexchange.techtarget.com/IT-watch-blog/cream-of-the-twitter-crop-storage-edition/', 'wp_slug': 'cream-of-the-twitter-crop-storage-edition', 'description': '<a href="http://http.cdnlayer.com/itke/blogs.dir/141/files/2010/06/follow.jpg"><img class="alignright size-medium wp-image-1148" style="margin: 4px" src="http://http.cdnlayer.com/itke/blogs.dir/141/files/2010/06/follow.jpg" alt="" width="279" height="157" /></a>Here they are, this month\'s specialized top 10 Twitter accounts. From IT pros with impressive storage insight to the industry greats sending out updates on their company\'s innovations, check out these folks on Twitter for daily bites of what you need to know about storage.\n<ul>\n\t<li><a href="http://twitter.com/3parfarley" target="_blank">3parfarley</a>: Marc Farley, the blogger behind StorageRap, sends out bite-sized bits of storage info. He\'s also one of <a title="Marc Farley" href="http://searchstorage.techtarget.com/expert/KnowledgebaseBio/0,289623,sid5_cid382505,00.html" target="_blank">SearchStorage.com\'s experts</a>.</li>\n\t<li><a href="http://twitter.com/storagenerve" target="_blank">StorageNerve</a>: Devang Panchigar is in the storage/virtualization/computer industry; he blogs over at StorageNerve and Gestalt IT.</li>\n\t<li><a href="http://twitter.com/skenniston" target="_blank">skenniston</a>: Follow the Storage Alchemist himself.</li>\n\t<li><a href="http://twitter.com/storageanarchy" target="_blank">StorageAnarchy</a>: From the blogger behind Storage Anarchy, get some storage rebel yells in 140 characters or less.</li><li>', 'title': 'Cream of the Twitter Crop: Storage Edition', 'post_status': 'publish', 'date_created_gmt': <DateTime '20100601T19:27:17' at 2853530>, 'mt_excerpt': '', 'userid': '288', 'dateCreated': <DateTime '20100601T14:27:17' at 28533a0>, 'custom_fields': [{'value': '', 'id': '1317', 'key': 'brightcove_code'}, {'value': 'http://bit.ly/d0Rywl', 'id': '1403', 'key': 'topsy_short_url'}, {'value': '1', 'id': '1319', 'key': '_edit_last'}, {'value': '1275511812', 'id': '1318', 'key': '_edit_lock'}, {'value': 'http://itknowledgeexchange.techtarget.com/IT-watch-blog/cream-of-the-twitter-crop-storage-edition/', 'id': '1402', 'key': '_topsy_long_url'}], 'wp_author_display_name': 'Melanie Yarbrough', 'link': 'http://itknowledgeexchange.techtarget.com/IT-watch-blog/cream-of-the-twitter-crop-storage-edition/', 'mt_text_more': u'<a href="http://twitter.com/storagetexan" target="_blank">StorageTexan</a>: He\'s got 15 years in the IT industry, 10 of them spent - proudly - as a storage geek.</li>\n\t<li><a href="http://twitter.com/storage_wonk" target="_blank">Storage_Wonk</a>: Xiotech\'s principle architect blogs over at Storage Wonk.</li>\n\t<li><a href="http://twitter.com/storageio" target="_blank">storageio</a>: Greg Schulz is an independent IT advisor and consultant, and he blogs over at the Storageio blog.</li>\n\t<li><a href="http://twitter.com/saveonstorage" target="_blank">SaveOnStorage</a>: If you\'re looking to lower your TCO, check out Hitachi Data Systems\' Twitter account dedicated to just that with sustainable storage investments. Vendor(ish).</li>\n\t<li><a href="http://twitter.com/seagate" target="_blank">Seagate</a>: The "world leader" in storage devices. Vendor(ish).</li>\n\t<li><a href="http://twitter.com/compellent" target="_blank">Compellent</a>: Compellent\'s official Twitter for all things enterprise storage. Vendor(ish).</li>\n</ul>\nAnd there\'s always us. <a href="http://twitter.com/itke" target="_blank">Follow ITKE on Twitter</a> for updates on the IT community and industry. Did we miss someone? Let me know at <a href="mailto:[email protected]" target="_blank">[email protected]</a> or at the <a href="http://itknowledgeexchange.techtarget.com/itanswers/" target="_blank">ITKE Community Forum</a>.\n\n<em>Melanie Yarbrough is the assistant community editor at\xa0<a title="http://ITKnowledgeExchange." href="http://itknowledgeexchange.com/" target="_blank">ITKnowledgeExchange.com</a>. Follow her on <a href="http://twitter.com/myarbrough" target="_blank">Twitter </a>or send her an email at <a href="mailto:[email protected]" target="_blank">[email protected]</a>.</em>', 'mt_allow_comments': 1, 'wp_password': '', 'postid': '1061', 'wp_author_id': '288', 'categories': ['Storage in 2010', 'Storage', 'Twitter'], 'mt_allow_pings': 1}] 

하지만 어떻게 난 그냥 그 날짜 시간 정보를 제공받을 수 있나요?

+1

'pprint'는 친구입니다. –

답변

2

이 사전 인 경우 print은 선행 및 후행 중괄호를 표시하며, 표시되는 내용은 아무데도 중간에서 시작하고 다른 중간에 끝납니다. 절대적으로 불합리합니다.

나는 이상한 사본과 과거의 오류를 만든 것으로 가정하고, 은 사전입니다.

편집

print blog.get_recent_posts(1)['dateCreated'] 
: 영업 이익이 전체 결과를 표시하는 Q 편집 (일부 도움이 오류 메시지를 언급), 모두 함께 그 경우, 예를 들어 점점 생성 날짜는 쉽게, 그냥 색인입니다 함수의 결과가 그 안에 하나의 사전이있는 목록임을 분명히합니다. 이 경우에 올바른 진술은 다음과 같이됩니다.

print blog.get_recent_posts(1)[0]['dateCreated'] 
+0

네 말이 맞아. 중간에서 복사하여 붙여 넣기 때문에 길고 못생긴 형태의 붙여 넣기를 피할 수 있습니다. 전체 결과물 인 사전으로 업데이트했습니다. 나는 당신이 제안한 것을 시도했지만 다음 오류가 발생했습니다. "TypeError : 목록 색인은 str이 아닌 정수 여야합니다". 나는 정수를 넣으려고 시도하고 하나의 값이라도 "범위를 벗어난 목록 색인"이라는 오류를 받았습니다. 포인터를 보내 주셔서 감사합니다! 그것은 내 자신의 수사에 매우 도움이됩니다. –

+0

아하, 그건 딕트가 아니야. 하나의 딕트가 들어있는 목록이다. ** 그저 ** 부분 출력만으로는 짐작할 수 없었다. 답변을 편집하여 원하는 것을 얻는 방법을 보여줍니다. –

관련 문제