[Tutor] import question

Glen Wheeler wheelege@tsn.cc
Wed, 4 Jul 2001 20:06:22 +1000


This is a multi-part message in MIME format.

------=_NextPart_000_011E_01C104C4.CBB32160
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

  Hey Tutorians,

  I've got a little query regarding importing.  Say I've got several =
modules, one main module and the others are specific functional modules.
  My problem is that I have a few classes defined in the main module, =
and these are useful to all the auxilary modules.  The badness?  Python =
spews when I try to do it.  In fact, I get very weird results.

###mainmodule###
import aux1,aux2,aux3

#--code--#

###aux1###
from mainmodule import uniclass

#--code--#

and when I try to run mainmodule pythonwin spits with an error in aux1 - =
saying mainmodule has no attribute uniclass, which is just wrong.  If I =
run it again then it dies when I try to use a class from aux1 (or any of =
the other modules), which makes sense if the original import died.
  I figured I could try something along the lines of...

###aux1###
uniclass =3D mainmodule.uniclass

#--code--#

  But of course this does not work.  Is there a way to refer to the =
module which imported the current module?  Like with bases in classes?

  Any help would be greatly appreciated,
  Glen.

------=_NextPart_000_011E_01C104C4.CBB32160
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4522.1800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp; Hey Tutorians,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; I've got a little query regarding importing.&nbsp; Say I've =
got=20
several modules, one main module and the others are specific functional=20
modules.</DIV>
<DIV>&nbsp; My problem is that I have a few classes defined in the main =
module,=20
and these are useful to all the auxilary modules.&nbsp; The =
badness?&nbsp;=20
Python spews when I try to do it.&nbsp; In fact, I get very weird =
results.</DIV>
<DIV>&nbsp;</DIV>
<DIV>###mainmodule###</DIV>
<DIV>import aux1,aux2,aux3</DIV>
<DIV>&nbsp;</DIV>
<DIV>#--code--#</DIV>
<DIV>&nbsp;</DIV>
<DIV>###aux1###</DIV>
<DIV>from mainmodule import uniclass</DIV>
<DIV>&nbsp;</DIV>
<DIV>#--code--#</DIV>
<DIV>&nbsp;</DIV>
<DIV>and when I try to run mainmodule pythonwin spits with an error in =
aux1 -=20
saying mainmodule has no attribute uniclass, which is just wrong.&nbsp; =
If I run=20
it again then it dies when I try to use a class from aux1 (or any of the =
other=20
modules), which makes sense if the original import died.</DIV>
<DIV>&nbsp; I figured I could try something along the lines of...</DIV>
<DIV>&nbsp;</DIV>
<DIV>###aux1###</DIV>
<DIV>uniclass =3D mainmodule.uniclass</DIV>
<DIV>&nbsp;</DIV>
<DIV>#--code--#</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; But of course this does not work.&nbsp; Is there a way to =
refer to=20
the module which imported the current module?&nbsp; Like with bases in=20
classes?</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Any help would be greatly appreciated,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_011E_01C104C4.CBB32160--