Import without executing module

Kottiyath n.kottiyath at
Mon Feb 2 02:25:17 EST 2009

On Feb 2, 12:19 pm, Stephen Hansen <apt.shan... at> wrote:
> On Sun, Feb 1, 2009 at 11:05 PM, Ray <rayky... at> wrote:
> > Basically, someone has created a python script and I would like to
> > make use of his functions.  I would prefer to not modify his file so
> > what I would like to do is just write my script and import parts that
> > are needed.  i.e., I would like to separate my changes from his as
> > best as I can.  However, that other module has both functions (def's,
> > which I would like to use) and top-level commands which I don't need
> > and in fact, prints errors when I import it since it was meant to be
> > run as a top-level module and not imported in.  i.e., its expecting
> > arguments to be supplied.
> Unfortunately, that's not possible, I believe. All the top level
> commands in a particular Python script are executed: that's how the
> functions get created.
> --S

Maybe he can wrap the things he dont need inside
if __name__ == '__main__':

More information about the Python-list mailing list