[Tutor] module import problems

Steven D'Aprano steve at pearwood.info
Mon Apr 26 05:09:51 CEST 2010

On Mon, 26 Apr 2010 11:56:06 am Rayon wrote:
> I have a module with the name _table
> in the same directory I have another by the name of _module
> I would like to import _table into _module
> can someone tall me how.

At the beginning of the _module module (what a name! yuck! don't you 
have a more descriptive name you can use?), put this line:

import _table

Then whenever you need something from _table, you write something like 

print _table.my_function("something")

> from tables.report_db_engine import *

Two comments:

What is "tables"? Is that the same as _table?

Generally you shouldn't use the "from module import *" form. You should 
consider it advanced usage, or at least discouraged.

Steven D'Aprano

More information about the Tutor mailing list