C/API importing a module as __main__

M

Miki Tebeka

Hello All,

Is there a way to import module as __main__?

Say hw.py is:

if __name__ == "__main__":
print "Hello"

And the C code is (error handling omitted):

int
main(int argc, char *argv[])
{
Py_Initialize();
PySys_SetArgv(argc, argv);

atexit(Py_Finalize);

PyImport_ImportModule(module);
return 0;
}

When importing hw using PyImport_ImportModule nothing is printed (as
expected).
The documentation says that Py_Initialize already creates a __main__ module
and hw.py is imported as hw.

Any way to import hw as __main__?

Thanks.
--
------------------------------------------------------------------------
Miki Tebeka <[email protected]>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)

iD8DBQFC0hPw8jAdENsUuJsRAmK1AJ0bOBp2Hc1zaVGIjoH6mu/IrQxbTwCfa2xc
Rlj8WqesH/ZVS1uwjnI+i+U=
=h63h
-----END PGP SIGNATURE-----
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top