AtributeError: module gameutils has no attribute 'ch'

AtributeError: module gameutils has no attribute 'ch'

所以我遇到了 main.py 的问题。然后我运行main.py,它给我一个属性错误。

gameutils.py:

class gameutils:                                         
  def main():                                              
    return True                                                       
  def ch():                                                
    input = ('What will you choose to do next? ')          
    print()                                                
    print('You\'ve chosen to ' + input + '.')              
    return input

和main.py:

from gameutils import ch

ch()

此外,gameutils.py 和 main.py 在同一目录中。可能是什么问题?我也在 Termux运行 中 Python 3 中

您正在导入模块(.py 文件)而不是 class。所以请尝试

from gameutils import gameutils 这将从 gameutils 模块加载 gameutils class 即 .py 文件

然后

gameutils.ch() # This is the actual class