Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I get an [AttributeError: module 'code' has no attribute 'Main'] error, but the attribute is clearly there. Why?

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."

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading