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 if

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, which is

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-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 yet, which

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

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

2007-04-27 Thread gtb
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? The last line of the sample below has a string parameter. When I mimicked this I got an error stating that the class constructor did not take an arg

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': 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 you cut

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

if __name__ == 'main':

2007-03-20 Thread gtb
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? Thanks, gtb == if __name__ == 'main': myQuest('myQuest').Run() -- http

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

Re: if __name__ == 'main':

2007-03-20 Thread Grant Edwards
here if it is not main? By importing the file. if __name__ == 'main': myQuest('myQuest').Run() -- Grant Edwards grante Yow! Thank god!!... It's at HENNY YOUNGMAN!! visi.com

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:\codetype temp.py print Module

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 main? A quick