Import without executing module
Ray
raykyoto at gmail.com
Mon Feb 2 21:37:55 EST 2009
Hi all,
On Feb 3, 1:11 am, John Machin <sjmac... at lexicon.net> wrote:
> On Feb 2, 11:51 pm, pyt... at bdurham.com wrote:
>
> > If the output is coming from a print command, couldn't the OP
> > temporarily redirect STDIO to a file to prevent the output from being
> > displayed?
>
> He could, but that'd be a kludge on top of a stuff-up. He should put
> the script-only statements inside
> if __name__ == '__main__':
> and send the result back to the original author, who may in fact
> appreciate being enlightened :-)
>
> Cheers,
> John
Thanks John and Malcolm! In my case the first solution would not
work. Sorry, that my simple "test" example was only a minimal one
which did not reflect the true problem. The module that I do not want
to edit not only runs on the command line and does some processing,
but also expects arguments. So, when reading it through importing, it
exits with an error (because no arguments were supplied).
I'll enclose the top-level commands with the if statement above...its
just a minor change, but it seems unavoidable.
Thanks again!
Ray
More information about the Python-list
mailing list