Python modules - Scopes

后端 未结 1 935
北海茫月
北海茫月 2021-01-27 18:40

I found what I think is peculiar behaviour by python 3.4. I made these small files to illustrate the problem I am facing.

To focus on the problem, I now have a python pr

相关标签:
1条回答
  • 2021-01-27 19:33

    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.

    0 讨论(0)
提交回复
热议问题