On May 14, 2009, at 5:28 AM, Dag Sverre Seljebotn wrote:

> Robert Bradshaw wrote:
>>
>>> An additional idea (not implemented) - it would be awesome to  
>>> have the
>>> first module listed (that is, the one directly imported) to have
>>> __name__ == "__main__", so the normal Python idiom works.  I
>>> researched this for the past few hours, but I could not find a  
>>> way to
>>> do this without modifying the module's code.  My best solution is  
>>> the
>>> following:
>>> 1. For each module, mymod.pyx:
>>> 1a. Add a new externally-visible global variable:
>>>     int __pyx_mymod_is___main__ = 0;
>>> 1b. When converting the code for __name__, if  
>>> __pyx_mymod_is___main__,
>>> return "__main__", else the module name.
>>> 2. In the script below, set
>>>     __pyx_mainmod_is___main__ = 1;
>>> right before the call to PyImport_ImportModule(), where "mainmod" is
>>> the main module.
>>
>> Done. The flag is __pyx_module_is_main_[fullyqualifiedname.replace
>> ('.', '__')]
>>
>
> This apparently broke stuff when embed is not turned on. A quick
> hackaround at
>
> http://hg.cython.org/cython-devel/rev/efe5cac433da
>
> but you will have to look.

Oops. Yes.

- Robert


_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to