在您的情况下,您可能想要的是:
"flickr = flickrapi.FlickrAPI(api_key)
photos = flickr.photos_search(user_id='73509078@N00', per_page='10')
sets = flickr.photosets_getList(user_id='73509078@N00')"
- flickrapi 文档
所以它所做的是获取返回XML doc
并作为ElementTree
对象提供给您,因此更容易处理。(这是sets
对象)。不幸的是,照片对象无法做到这一点。
元素树文档
因此,要获得属性的一般列表,首先使用传递给您的树的根节点的.tag
和方法。.attrib
root
您可以在 ElementTree 文档中的示例中使用集合:)
它给出的一个例子是:
sets = flickr.photosets_getList(user_id='73509078@N00')
sets.attrib['stat'] => 'ok'
sets.find('photosets').attrib['cancreate'] => '1'
set0 = sets.find('photosets').findall('photoset')[0]
+-------------------------------+-----------+
| variable | value |
+-------------------------------+-----------+
| set0.attrib['id'] | u'5' |
| set0.attrib['primary'] | u'2483' |
| set0.attrib['secret'] | u'abcdef' |
| set0.attrib['server'] | u'8' |
| set0.attrib['photos'] | u'4' |
| set0.title[0].text | u'Test' |
| set0.description[0].text | u'foo' |
| set0.find('title').text | 'Test' |
| set0.find('description').text | 'foo' |
+-------------------------------+-----------+
... and similar for set1 ...
-flickrapi 文档
您可能一直在间接问的另一个问题:
一般来说,给定一个 pythonclass
你可以这样做:
cls.__dict__
获取一些可用的属性。
给定一个通用的 python 对象,您可以使用vars(obj)
或dir(obj)
例如:
class meh():
def __init__(self):
self.cat = 'dinosaur'
self.number = 1
# some example methods - don't actually do this
# this is not a good use of a method
# or object-oriented programming in general
def add_number(self, i):
self.number+=i
j = meh()
print j.__dict__
{'number': 1, 'cat': 'dinosaur'}
这将返回用于对象的命名空间的字典:
“除了一件事。模块对象有一个名为dict的秘密只读属性,它返回用于实现模块名称空间的字典;名称dict是一个属性而不是全局名称。显然,使用它违反了名称空间实现的抽象,并且应该仅限于事后调试器之类的东西。” - Python 文档
dir
返回
"Without arguments, return the list of names in the current local
scope. With an argument, attempt to return a list of valid attributes
for that object." docs
and
vars
just returns the dict attribute:
"return the dict attribute for a module, class, instance, or any
other object with a dict attribute.
Objects such as modules and instances have an updateable dict
attribute; however, other objects may have write restrictions on their
dict attributes (for example, new-style classes use a dictproxy to prevent direct dictionary updates)." docs
it should be noted that nothing can give you everything available to an object at run time due to crafty things you can do to modify an object.