Scope question

Steve Holden sholden at holdenweb.com
Fri Feb 8 08:44:13 EST 2002


"Paul Rubin" <phr-n2002a at nightsong.com> wrote in message
news:7xpu3gixt2.fsf at ruckus.brouhaha.com...
> "MDK" <mdk at mdk.com> writes:
> > > from  mymod import *
> > > mymod_dosomething = dosomething
> > >
> > > def dosomething(x):
> > >     mymod_dosomething(1000)
> > >
> > > Neal
> >
> > Neat!  Thanks, Neal.
>
> Alternatively, in Python 2.x,
>
>   from mymod import dosomething as mymod_dosomething
>
> Generally, it's best to avoid "from mymod import *", precisely
> because of collisions like this.  As other people have mentioned, it's
> better to say
>
>   import mymod
>
>   def dosomething(x):
>     mymod.dosomething(1000)

We should not overlook the third alternative (nobody expects ...) which is
to write

    from mymod import dosomething as banana

    def dosomething(x):
        banana(1000)

When I use the mxDateTime module I frequently write

    from mx.DateTime import DateTime as dt

just because (as regular readers will know) I'm a crappy typist.

still-wondering-why-dosomething-has-an-argument-ly y'rs  - steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Author, Python Web Programming: http://pydish.holdenweb.com/pwp/

"This is Python.  We don't care much about theory, except where it
intersects with useful practice."  Aahz Maruch on c.l.py







More information about the Python-list mailing list