[Tutor] Importing modules/classes

Alan G alan.gauld at freenet.co.uk
Thu Aug 25 08:38:38 CEST 2005


>   Am trying to get my head around classes in python.

Looks like you have the classes bit figured out! :-)

> import dummy_class
> d=dummy_class()

But you have a problem with namespaces.

the class 'dummy_class' is inside the module 'dummy_class'
So when you import the module that allows you to use the 
name 'dummy_class' to refer to the *contents* of that module.

To access the class 'dummy_class' you need to prepend it 
with the name of the module:

d = dummy_class.dummy_class()

You can get more on this in the 'Whats in a Name?' topic of 
my tutor. And more on OOP in the OOP topic - naturally! :-)

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


More information about the Tutor mailing list