0

So hello again. I noticed I have not been asking the best python questions, but pray, bear with me. I have been working with classes to adopt the OOP method, even though I like it not. So now I am trying to import a class from a file in the same directory as my main file, but it just gives me a ModuleNotFoundError (hate how long this name is). So here is the code from the main file:

import class_
ahmed = class_.Name('Ahmed')
ahmed.show()

And here is the code from the file I want to import:

class Name():
    def __init__(self, name):
        self.name = name
    def show(self):
        print(self.name)

I know I made some dum dum mistake over here, but what is it?

Bored Comedy
  • 187
  • 9

1 Answers1

0

You should name your file which you want to import your code as class_.py and make sure it is in the same directory as the main file and this should work.

mmz
  • 23
  • 4
  • That's the exact problem! It's in the same directory, named after what you proposed, and yet it still gives me an error. – Bored Comedy Mar 03 '20 at 22:50
  • It worked for me. Check if you have accidentally capitalized or misspelled your file name – mmz Mar 04 '20 at 03:07