Re: Import without executing module

2009-02-10 Thread rdmurray
Lie Ryan wrote: > On Tue, 03 Feb 2009 20:08:34 -0800, Stephen Hansen wrote: > > > There is no need to try to make sure something is > > executed/compiled only once in Python like you may want to do in C. > > Every module is only ever compiled once: if you import it ten times in > > ten different

Re: Import without executing module

2009-02-10 Thread Lie Ryan
On Tue, 03 Feb 2009 20:08:34 -0800, Stephen Hansen wrote: > There is no need to try to make sure something is > executed/compiled only once in Python like you may want to do in C. > Every module is only ever compiled once: if you import it ten times in > ten different places only the first will co

Re: Import without executing module

2009-02-03 Thread Ray
Hi Stephen, On Feb 4, 1:08 pm, Stephen Hansen wrote: > On Tue, Feb 3, 2009 > > > 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

Re: Import without executing module

2009-02-03 Thread Stephen Hansen
On Tue, Feb 3, 2009 > 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? That statement is very common in P

Re: Import without executing module

2009-02-03 Thread Ray
Hi Lie, On Feb 3, 7:21 pm, Lie wrote: > On Feb 3, 1:37 pm, Ray 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 (dep

Re: Import without executing module

2009-02-03 Thread Lie
On Feb 3, 1:37 pm, Ray 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 i

Re: Import without executing module

2009-02-02 Thread Ray
Hi all, On Feb 3, 1:11 am, John Machin wrote: > On Feb 2, 11:51 pm, pyt...@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

Re: Import without executing module

2009-02-02 Thread Steve Holden
Taskinoor Hasan wrote: [...] > It make sense :-). So my reasoning..let A is imported in B, i.e. > name A is put in B's namespace. When we call something like A.a then the > interpreter first resolve A in B's namespace, then to get a, it need to > look up A's namespace. And there is no way to p

Re: Import without executing module

2009-02-02 Thread John Machin
On Feb 2, 11:51 pm, pyt...@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

Re: Import without executing module

2009-02-02 Thread python
3:19:09 -0800 Subject: Re: Import without executing module On Sun, Feb 1, 2009 at 11:05 PM, Ray 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

Re: Import without executing module

2009-02-02 Thread Ray
Hi Stephen and everyone, On Feb 2, 4:36 pm, Stephen Hansen wrote: > > Maybe he can wrap the things he dont need inside > > if __name__ == '__main__': > > check. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Yeah but he said he doesn't want to modify the file itself-- if he c

Re: Import without executing module

2009-02-02 Thread Taskinoor Hasan
On Mon, Feb 2, 2009 at 1:58 PM, Stephen Hansen wrote: > On Sun, Feb 1, 2009 at 11:43 PM, Taskinoor Hasan > wrote: > > Can anyone explain what is the necessity of executing whole script when > > importing. Isn't it enough to just put the module name in the namespace > and > > execute when some fun

Re: Import without executing module

2009-02-01 Thread Stephen Hansen
On Sun, Feb 1, 2009 at 11:43 PM, Taskinoor Hasan wrote: > Can anyone explain what is the necessity of executing whole script when > importing. Isn't it enough to just put the module name in the namespace and > execute when some function is called? I'm not sure if I'm going to explain this right--

Re: Import without executing module

2009-02-01 Thread Taskinoor Hasan
Can anyone explain what is the necessity of executing whole script when importing. Isn't it enough to just put the module name in the namespace and execute when some function is called? On Mon, Feb 2, 2009 at 1:36 PM, Stephen Hansen wrote: > > Maybe he can wrap the things he dont need inside > >

Re: Import without executing module

2009-02-01 Thread Stephen Hansen
> Maybe he can wrap the things he dont need inside > if __name__ == '__main__': > check. > -- > http://mail.python.org/mailman/listinfo/python-list > Yeah but he said he doesn't want to modify the file itself-- if he can modify the file this can all go away readily, yes. --S -- http://mail.python

Re: Import without executing module

2009-02-01 Thread Kottiyath
On Feb 2, 12:19 pm, Stephen Hansen wrote: > On Sun, Feb 1, 2009 at 11:05 PM, Ray 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 pa

Re: Import without executing module

2009-02-01 Thread Stephen Hansen
On Sun, Feb 1, 2009 at 11:05 PM, Ray 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 separ