Python icon indicating copy to clipboard operation
Python copied to clipboard

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

Open csoriano1618 opened this issue 11 years ago • 1 comments

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

csoriano1618 avatar Feb 01 '14 01:02 csoriano1618

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 ...

kenny-evitt avatar Dec 06 '15 23:12 kenny-evitt