Python modules - Scopes

橙三吉。 提交于 2019-12-02 09:18:59

The problem you're running into is that when peculiar.py is run as a script, it is not considered to be the peculiar module. It is considered to be the __main__ module. Importing peculiar will run the file again, producing a separate copy of the Point class, the points_list list, and so on.

I recommend separating your program's main functionality into a separate file that imports peculiar and calls the versions of everything from the peculiar module. Alternatively, you can use import peculiar; peculiar.main() in your if __name__ == "__main__" block.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!