Ed Leafe wrote: > On Oct 31, 2004, at 4:39 PM, Paul McNett wrote: > >> I don't think so. What you could do is just assume that if daborun is >> being run with that script as a parameter, that we want to execute it >> if it has a main() function. > > > Yeah, that's what I had in my first incarnation, but so many things > in Dabo (Dabo Editor, appRecipes demo, appWizard, FieldSpecEditor, and > the SimpleForm... programs) don't use a 'main()' method - the execution > code runs after the 'if __name__' test - that I wanted to see if there > was a more generic way of dealing with this. If not, we can change all > the demo code to use a main() method, and decree that henceforth all > Dabo code shall have a main() method. ;-)
I think that is better (more explicit). We could even consider using something other than main(), such as daborun() or something, so that people can decide whether their code can run as a script, in daborun, or both:
def main(): # Runs if we are run as a script. def daborun(): # Runs if we are called from daborun. # User code can do additional stuff, and conditionally choose to # call the main() function - user code "knows" that it is being # run from daborun. This may prove fruitful in the future for # reasons unbeknownst to us now. main() if __name__=="__main__": # We know we are the main script. main()
I say this only because we are now in the position to name it, and in the future we'll have to live with the decision. Many Python scripts will have main() functions, so perhaps it would be better if we chose something that pretty much guarantees the given script is a dabo script.
-- Paul McNett - http://paulmcnett.com vcard: http://paulmcnett.com/pm.vcf
©2004 Paul McNett |