Re: if __name__ == 'main': & passing an arg to a class object

2007-04-30 Thread Steven D'Aprano
On Sun, 29 Apr 2007 07:32:44 -0400, Bart Willems wrote: > gtb wrote: >> appear at the end of many examples I see. Is this to cause a .class >> file to be generated? > This might be obvious, but no one else mentioned it: the Python > interpreter cannot execute code that it hasn't compiled yet, whi

Re: if __name__ == 'main': & passing an arg to a class object

2007-04-30 Thread Duncan Booth
Bart Willems <[EMAIL PROTECTED]> wrote: > gtb wrote: >> appear at the end of many examples I see. Is this to cause a .class >> file to be generated? > This might be obvious, but no one else mentioned it: the Python > interpreter cannot execute code that it hasn't compiled yet, which is > why the

Re: if __name__ == 'main': & passing an arg to a class object

2007-04-29 Thread John Machin
On Apr 29, 9:32 pm, Bart Willems <[EMAIL PROTECTED]> wrote: > gtb wrote: > > appear at the end of many examples I see. Is this to cause a .class > > file to be generated? > > This might be obvious, but no one else mentioned it: the Python > interpreter cannot execute code that it hasn't compiled ye

Re: if __name__ == 'main': & passing an arg to a class object

2007-04-29 Thread Bart Willems
gtb wrote: > appear at the end of many examples I see. Is this to cause a .class > file to be generated? This might be obvious, but no one else mentioned it: the Python interpreter cannot execute code that it hasn't compiled yet, which is why the "if __name__ ..." code is always at the end of the

Re: if __name__ == 'main': & passing an arg to a class object

2007-04-28 Thread Bjoern Schliessmann
alisonken1 wrote: [if __name__ == "__main__"] > These are samples to give the programmer an idea of how the code > is supposed to work. No, this belongs into comments or docs. The contents of this block are often used for testing or debugging, or for normally executable code if it makes sense to

Re: if __name__ == 'main': & passing an arg to a class object

2007-04-27 Thread gtb
Sorry for the wrong implication. I should have said I 'mimicked the style'. No, not used to Java at all, and obviously not versed in python either (do I get points for tcl?). Maxq generates jython scripts and when I saw the .class files I assumed it was the work of the python compiler as what is v

Re: if __name__ == 'main': & passing an arg to a class object

2007-04-27 Thread alisonken1
On Apr 27, 2:08 pm, gtb <[EMAIL PROTECTED]> wrote: > The lines > > if __name__ == 'main': >someClass().fn() > > appear at the end of many examples I see. Is this to cause a .class > file to be generated? > These are samples to give the programmer an idea of how the code is supposed to work. If

Re: if __name__ == 'main': & passing an arg to a class objec

2007-04-27 Thread Daniel Nogradi
> The lines > > if __name__ == 'main': >someClass().fn() > > appear at the end of many examples I see. Is this to cause a .class > file to be generated? Python doesn't generate .class files, and the example you mean is probably more like if __name__ == '__main__': .whatever...

Re: if __name__ == 'main':

2007-03-20 Thread gtb
On Mar 20, 12:13 pm, "Patrick Down" <[EMAIL PROTECTED]> wrote: > On Mar 20, 11:49 am, "gtb" <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I often see the following 'if' construct in python code. What does > > this idiom accomplish? What happens if this is not main? How did I get > > here if it is not

Re: if __name__ == 'main':

2007-03-20 Thread Patrick Down
On Mar 20, 11:49 am, "gtb" <[EMAIL PROTECTED]> wrote: > Hi, > > I often see the following 'if' construct in python code. What does > this idiom accomplish? What happens if this is not main? How did I get > here if it is not main? A quick example demonstrates the usage: C:\code>type temp.py prin

Re: if __name__ == 'main':

2007-03-20 Thread Grant Edwards
On 2007-03-20, gtb <[EMAIL PROTECTED]> wrote: > I often see the following 'if' construct in python code. What does > this idiom accomplish? It checks to see if the file is being run as the "main" program, and does something if that is so. > What happens if this is not main? Nothing. > How did

Re: if __name__ == 'main':

2007-03-20 Thread Facundo Batista
gtb wrote: > I often see the following 'if' construct in python code. What does > this idiom accomplish? What happens if this is not main? How did I get > here if it is not main? > ... > if __name__ == 'main': >myQuest('myQuest').Run() This idiom is for executing the code if you're running t