Python NameError The class of the name is not defined but it actually is -


i playing classes , thought create class called container meant group things can hold other things.

# -*- coding: utf-8 -*-  class container(object):     def __init__(self, name, volume):         self.name = name         self.max_volume = volume  hands = container('hands', 2) 

i started point , wanted test if ok if in python console call hands.name says hands not defined. happens when import module too.

i don't doint wrong! can please explain me how make work?

i python console:

traceback (most recent call last):   file "<stdin>", line 1, in <module> nameerror: name 'hands' not defined 

assuming container.py file:

# -*- coding: utf-8 -*-  class container(object):     def __init__(self, name, volume):         self.name = name         self.max_volume = volume  hands = container('hands', 2) 

and execution command in interpreter:

>>> import container 

then, hands instance accessible in following manner:

>>> container.hands.name 

to avoid container prefix, can this:

>>> container import hands >>> hands.name 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -