[Tutor] quick OO pointer

Alan Gauld alan.gauld at freenet.co.uk
Mon Aug 7 19:22:51 CEST 2006


> If my script that needs to call a function from another module, and 
> the
> module itself both require, say, the string module.... do i need to 
> import
> it in both?

Yes, importing just makes the name visible in the module where it is 
imported.

So if you import your module the stuff that it imported is not 
visible.

But you really need to look at all the options around importing
because there are several options:

import mymodule
import mymodule as anothername
from my module import myfunc
from mymodule import *

The last technique is frowned upon except in special cases.
But you should really read about all the options to understand
exactly what each does for you.

> If i just import string on my original script, will the module
> know what to do with it?

Not sure what you mean. The module does nothing with it.
Its up to you to write code that uses it. It will be available
inside the module after the import and you can access its
functions in turn by prefixing them.

Think of it a bit like a bit containment graph where each
node in the graph can refer to any other node. Where you
get cycles then you can get problems so you should try to
avoid those situations.

HTH,

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



More information about the Tutor mailing list