Capturing the entry point of a script

S

SamG

If a function does not have main function defined and there is only a

if __name__="__main__":

how do i make a call to that using

profile.runcall( ...)

in my profiling script. Is there a way to find the entry point of a
script and indentify it with module method.
 
S

Steve Holden

SamG said:
If a function does not have main function defined and there is only a

if __name__="__main__":

how do i make a call to that using

profile.runcall( ...)

in my profiling script. Is there a way to find the entry point of a
script and indentify it with module method.
There is no way to do that without modifying your module (by the way, I
think you should have said "If a *module* does not ...").

The easiest way to do this is to replace the line

if __name == "__main__:

with

def main():

and then at the end of the module put

if __name__ == "__main__":
main()

The second step is not required unless you still want the module to run
as a standalone script.

Now you can call profile.runcall(module.main, ...)

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,810
Messages
2,569,692
Members
45,468
Latest member
VanitaCrum

Latest Threads

Top