Home > Net >  I get an [AttributeError: module 'code' has no attribute 'Main'] error, but the
I get an [AttributeError: module 'code' has no attribute 'Main'] error, but the

Time:08-27

I'm trying to link a Discord bot to a text-game I made, but when I attempt to call the Class of the game itself, it tells me,

AttributeError: module 'code' has no attribute 'Main'

Here's my code:

# bot.py
import code # Import the code for the actual game

main = code.Main() # Begin the game's processes
# code.py
class Main:

    def __init__(self):
        self.otherModule() # This module is used to continue the flow throughout the class

I can't see what's wrong with it. When I try to look it up, I'm only told to "just give it a class."

CodePudding user response:

Rename code. The module code already exists as a built-in module in Python3.

Python 3.10.4
Type "help", "copyright", "credits" or "license" for more information.
>>> import code
>>> print(code)
<module 'code' from '/usr/lib/python3.10/code.py'>

Source: https://docs.python.org/3/library/code.html#module-code

  • Related