Huh?!?!? What is it that I'm seeing here?

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Sep 15 01:12:25 CEST 2003


>>>>> "Don" == Don Bruder <dakidd at sonic.net> writes:


    Don> if __name__ == '__main__': run(argv[1:])

You can safely ignore these in your conversion project.  

  if __name__ == '__main__'

This means if the text file "somefile.py" holding the module code is
run as the main file, as in 

  > python somefile.py
or 
  > ./somefile.py 
if the file has an executable bit set

  run(argv[1:])

This means "call the function run, passing command line arguments as
arguments".

Basically, the code at the bottom allows any python module to save the
same purpose as the C/C++ function 'main'.  Once you have converted
the python module, and implemented the function "run" in your C/C++
code, you would do something like

int main( int argc , char** argv ) {
  run(argv);
}

Cheers,
John Hunter





More information about the Python-list mailing list