python - Name not definef error when using Class -


i facing issue code framed class.

basically before file functions defined in it.

so when trying execute file using command python filename.py, working fine needed.

code sample follows:

# getting tenant list  # fetch creation_date of tenant if exists def get_tenants():      # fetch tenant list     tenants_list = keystone.tenants.list()      # fetch tenant id     tenant in tenants_list:         tenant_id = tenant.id . . .  get_tenants() 

so shown in aboce code in file trying call get_tenants function, working fine needed no error.

now have created class moved functions in same.

above function rewritten follows now.

def get_tenants(self):          # fetch tenant list         tenants_list = keystone.tenants.list()          # fetch tenant id         tenant in tenants_list:             tenant_id = tenant.id 

then have called function follows:

billing = billingengine() billing.get_tenants() 

but, getting error follows:

root@devstack:/opt/open-stack-tools/billing# python new_class.py traceback (most recent call last):   file "new_class.py", line 281, in <module>     billingengine().get_tenants()   file "new_class.py", line 75, in get_tenants     tenants_list = keystone.tenants.list() nameerror: global name 'keystone' not defined 

note: provide full file if needed.

may must define this?

class example(object):     keystone = keystone()     def get_tenants(self):        self.keystone.do_something() 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -