如何在python模块中列出对象的属性?

时间:2015-06-24 03:18:57

标签: python object

例如,在这个python模块中: https://github.com/bigcommerce/bigcommerce-api-python 如果我运行此代码:

#!/usr/bin/env python2
import bigcommerce
import bigcommerce.api

# Bigcommerce credentials and path
BIG_URL = 'store-45eg5.mybigcommerce.com'
BIG_USER = 'henry'
BIG_KEY = 'api_key'

# api object definition
api = bigcommerce.api.BigcommerceApi(host=BIG_URL, basic_auth=(BIG_USER, BIG_KEY))

def create_category(name):
    rp = api.Categories.create(name=name)
    #if rp.status_code == 201:
    print(rp.status_code)
create_category('anothernewtestingcat12345')

我得到了这个追溯:

Traceback (most recent call last):
  File "./littletest.py", line 17, in <module>
    create_category('anothernewtestingcat12345')
  File "./littletest.py", line 16, in create_category
    print(rp.status_code)
AttributeError: 'Categories' object has no attribute 'status_code'

我的问题是,在这种情况下,是否可以获得给定对象的属性列表?或者我是否必须参考文档来确定Categories对象将具有哪些属性?

这个问题不是特定于bigcommerce python api,它是关于如何确定给定对象属性的一般性问题,我只是以bigcommerce python api为例。

1 个答案:

答案 0 :(得分:1)

passwordChanged