LightTable / Python

Python language plugin for Light Table
MIT License
98 stars 51 forks source link

Code inside if __name__=="__main__": not executed when ctrl + enter #11

Open csoriano1618 opened 10 years ago

csoriano1618 commented 10 years ago

Seems the code inside if name=="main": is not executed, and just the plain code outside all definitions are executed. afaik if name=="main" is a common way to define code to be excuted, so imho lighttable should execute that code when ctrl + enter

kenny-evitt commented 8 years ago

This is probably because of the behavior described in LightTable/LightTable#760, i.e. the whole file is imported so that the relevant plugin code can reference the 'module' object. This comment in the aforementioned issue has more possibly relevant details. One thing it mentions is that code inside the if __name__ == "__main__": is NOT executed when evaling in LT and that:

This is the standard Python move and will stop that code being run on import ...