C/API importing a module as __main__

Miki Tebeka miki.tebeka at zoran.com
Mon Jul 11 02:38:40 EDT 2005


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 <miki.tebeka at zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 193 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050711/4329c2b2/attachment.sig>


More information about the Python-list mailing list