Scope question
Philip Swartzleonard
starx at pacbell.net
Fri Feb 8 22:36:11 EST 2002
phil hunt || Thu 07 Feb 2002 03:45:43p:
> On Thu, 7 Feb 2002 10:26:02 -0500, MDK <mdk at mdk.com> wrote:
>>I have this:
>>
>># myprog.py
>>
>>from mymod import *
>>
>>def dosomething(x): dosomething(1000)
>>
>># End code
>>
>>I want the dosomething(1000) run from the function in mymod. However,
>>instead it is running dosomething(x) in myprog.py.
>
> Do:
>
> # myprog.py
> import mymod
> def dosomething(x):
> mymod.dosomething(1000)
>
>>import mymod
>
> Thisi s the prefered way of doing things.
Yet another thing you can do, if you really want the import * too, is to
just add 'import mymod' underneath it. This won't add anything but a
name to the current namespace -- the module's already been initilized.
I wouldn't really reccommend it, but as i'm importing * from GL/GLU/GLUT
and wx, i also import the modules themselfs so i can get there
__dicts__, and filter all that crap out of the dictionary I pass to
pycrust :).
I may stop doing this in the future though... i think i may make a
module 'interface' and do 'form xxx import *'s in there, so then import
it as 'i'. i.wxFrame, i.glutPostRedisplay, etc (it would also be nice if
there was a sperate module of the GL's that didn't preface GL infront of
everything. gl.vertex3d looks a lot better than gl.glVertex3d... :)
Ah.. goin' off on a tanget again...
Z'out
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list