Pyrex installation on windows XP: step-by-step guide

greg greg at
Sat May 27 11:31:26 CEST 2006

Jim Lewis wrote:
> Thanks but now another problem :-(
> Examples in books show importing a global so why does below give:
> AttributeError: 'module' object has no attribute 'globalvar'
> primes.pyx:
> from run import globalvar
> def prime(int kmax):
>   result = [run.globalvar]
> ...
> from primes import prime
> globalvar = 999
> while True:
> 	print prime (10)

The first thing run does is import primes, which
immediately imports run and tries to access the
name globalvar in it, before it has been defined.

There are ways of fixing that, but for various
reasons it's usually a bad idea for subsidiary
modules to try to import things from the main
module of a program. It would be better to move
globalvar into a third module.

Even better again would probably be not to use
a global at all, but pass it in as a parameter
to the prime() function.


More information about the Python-list mailing list