Import without executing module

Stephen Hansen apt.shansen at gmail.com
Mon Feb 2 02:19:09 EST 2009


On Sun, Feb 1, 2009 at 11:05 PM, Ray <raykyoto at gmail.com> 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



More information about the Python-list mailing list