Ticket #65 (closed enhancement: fixed)

Opened 9 months ago

Last modified 7 months ago

Way to determine if a script is being run as a script or just being imported

Reported by: JarrettBillingsley Assigned to: JarrettBillingsley
Priority: normal Milestone: MiniD 2
Component: Interpreter Keywords:
Cc:

Description (Last modified by JarrettBillingsley)

Python has the (kind of odd) "if __name__ == "__main__":" to determine this. It'd be nice to have.

Change History

03/09/08 17:08:18 changed by JarrettBillingsley

  • description changed.

03/09/08 17:58:53 changed by Ligustah

I know that trick of python, however, i don't really like the way they implemented it. IMHO it is somehow ugly. I bet there are better ways to implement it, maybe something like:

main function(vararg)
{
//...do main stuff here...
}

So that you add the keyword 'main' for a new function literal, which creates an anonymous main function, which is not executed, when the module is just imported. To go with that, you could maybe add a runMain([module]) function to he Stdlib. What do you think about it?

Ligustah

04/27/08 16:24:30 changed by JarrettBillingsley

Sorry I never got back to this. I agree that the Python way of doing it is terribly unintuitive and ugly. I'm thinking that this could be done entirely without language changes, now that you've suggested the runMain function. runMain would just look for a global function named "main" in the given namespace, and run it with the (optional) varargs.

I really like that idea :D

04/27/08 18:18:20 changed by JarrettBillingsley

  • status changed from new to closed.
  • resolution set to fixed.

(In [292]) Closes #65. Also fixed a bug in the regexp.email predefined regexp, and a small bug in dumpVal.