name space problem

BBands bbands at gmail.com
Tue Oct 23 22:34:38 EDT 2007


On Oct 23, 4:20 pm, marek.ro... at wp.pl wrote:
> Hello. Indeed the doStuff function in the doStuff module can't do 'a.b
> = 0' (the double dot was just a typo, right?)

Yes.

> because it doesn't know anything about an object named a.

I was trying to understand why it worked when written in, but not when
included.

> I think the right solution would be not to use 'a' as a global
> variable, but rather to pass it as an explicit parameter to the
> function.

Does doing this make a copy of a?

> In module doStuff:
>
> def doStuff(a):
>     # some calcs
>     a.b = 0
>
> In the main module:
>
> import doStuff
> # ...
> doStuff.doStuff(a)

In my real ap a is quite large...

    thanks,

    jab




More information about the Python-list mailing list