2

I'm new to python and I have a hard time trying to figuring out how can I inherit from a class in an other module.

module: ~/foo.py

import bar

class foo:
    def test(self)
        print("this is a test")

module: ~/bar.py

class bar(foo):
    def __init__(self):
        super().test()

As soon as bar is imported, I get this error message :

NameError: name 'foo' is not defined

1 Answer 1

5

If you want to refer to a name in another module then you must import it.

import foo

class bar(foo.foo):
   ...
Sign up to request clarification or add additional context in comments.

2 Comments

I tried that already, it doesn't works... I get the same message.
Why are you importing bar in foo?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.