Class problem: loosing my mind

Erik Max Francis max at alcyone.com
Sun Apr 27 00:14:26 EDT 2003


"" wrote:

> Seems pretty wierd that:
> 
> import gV
> 
> fails while:
> 
> from gV import gV
> 
> works.
	...
> P.S. Any of you 'language lawyers' feel free to enlighten me as to WHY
> this works and the other doesn't, I'm all ears!

It doesn't _fail_, it just didn't do what you thought it did.  The
confusion here is because you're not seeing the difference between
packages (a directory containing a __init__.py file, and some modules
and perhaps even other packages) and modules (things which contain
Python things in them).  You want the module, but you're asking for the
package.  The confusion arises is because you've named the module and
the package containing the one module the same thing.  There's no need
for them to be the same thing.  If ... is in PYTHONPATH and you have a
directory structure like this:

	.../package/
	.../package/__init__.py
	.../package/module.py

and .../package/module.py contains an object x, then I need to access x
by importing the _module_, not the package.  So I need to write:

	import package.module; package.module.x
	from package import module; module.x
	from package.module import x; x

or something along those lines.  Yours is just a generate case where x
is in a module named blah, which is itself in a package named blah, so 

	import blah

imports the package named blah, not the module, which is what you really
wanted.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ But tell me, who _are_ they, these wanderers ... ?
\__/ Rainer Maria Rilke
    ZOE / http://www.alcyone.com/pyos/zoe/
 A simple Python OpenGL rendering engine.




More information about the Python-list mailing list