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?

2
  • 1
    Do you have a __init__.py in the same directory? Commented Mar 2, 2020 at 22:02
  • @CoryKramer Ummm...what's that? Commented Mar 3, 2020 at 1:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That's the exact problem! It's in the same directory, named after what you proposed, and yet it still gives me an error.
It worked for me. Check if you have accidentally capitalized or misspelled your file name

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.