Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Python 3.4.3 中编写了一个国际象棋程序,并在交互模式下运行 Python 3 解释器,如下所示:
python3 -i chess.py
但是,类定义之后的代码被调用了两次,我不知道为什么。我的代码在pastebin
您应该删除from chess import *文件末尾的行,它不应该是必需的。
from chess import *
此外,通常要确保某些代码不会被执行,除非模块中的代码作为脚本执行。
if __name__ == '__main__': # Not executed if the module is imported g = Game()