Hi Lie,

On Feb 3, 7:21 pm, Lie <lie.1...@gmail.com> wrote:
> On Feb 3, 1:37 pm, Ray <rayky...@gmail.com> wrote:
>
> > I'll enclose the top-level commands with the if statement above...its
> > just a minor change, but it seems unavoidable.
>
> > Thanks again!
>
> > Ray
>
> If you really don't want the file to be changed, you could (depends on
> the module) use the module as a subprocess. The ideal solution is for
> the module to have an if __name__ == '__main__': to determine whether
> it is being used as a module or a standalone program though.


Thank you for this!  I've done the "if __name__ ..." as you and others
suggested.  It isn't what I would have liked, but I'm ok with
it...especially after finding out that top-level code has to be run
while importing.  As I'm new to python, I didn't know about that, but
I now see there's no way around it.

So, is inserting the above if statement common practice for python
programmers?  As a C programmer, it seems that people put a "#ifndef
XXX...#define XXX...[all of the code]...#endif" almost as a habit.  I
wonder if its the same thing?

Thank you!

Ray

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to