0

For example, in this python module: https://github.com/bigcommerce/bigcommerce-api-python If I run this code:

#!/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')

I get this traceback:

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'

My question is, in this context, is it possible to get a list of the attributes of a given object? Or would I have to refer to the documentation to determine what attributes the Categories object would have?

This question is not specific to the bigcommerce python api, it's a general question about how to determine the attributes of a given object, I've just used the bigcommerce python api as an example.

2
  • 1
    try rp.__dict__ or dir(rp), and you can div into the difference to learn more Commented Jun 24, 2015 at 4:01
  • Thank you. What do you mean by "div into the difference"? Commented Jun 24, 2015 at 4:18

1 Answer 1

2
>>> class Simple:
...   def fun(self):
...     pass
...
>>> dir(Simple)
['__doc__', '__module__', 'fun']
>>> s = Simple()
>>> dir(s)
['__doc__', '__module__', 'fun']
>>> hasattr(s, 'fun')
True
Sign up to request clarification or add additional context in comments.

1 Comment

So in my example, would dir(api.Categories) be equivalent to dir(Simple) in your example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.