mcneel / ghpython

A Grasshopper component for Rhino.Python
http://www.food4rhino.com/project/ghpython
117 stars 34 forks source link

Make __main__ importable #64

Closed piac closed 8 years ago

piac commented 10 years ago

http://www.grasshopper3d.com/forum/topics/performance-profiling-in-ghpython

From a quick check, it seems that the solution is outlined in answer 1: http://stackoverflow.com/questions/8264596/how-do-i-set-name-to-main-when-using-ironpython-hosted

saeranv commented 8 years ago

Hello, I know it's been two years, but has this been addressed? I would like to use the timeit.timeit method and I'm running into the same namespace error the parent had: I cannot import methods from main. Is there a way to achieve this?

piac commented 8 years ago

Hi @saeranv, I had actually looked at this and our is a different case.

The 'real' reason is that there is no main. And there is no main because in GhPython there is no file: you can imagine it as code were run from the 'exec' function.

However, this is usually a minor problem. We can work around this (now; I think earlier the version of timeit was not supporting IronPython).

I uploaded a sample at the address: http://www.grasshopper3d.com/xn/detail/2985220:Comment:1520589

I will close this bug item, as there is no way to import this as a nameless module (it's like the interactive interpreter).