NameError When Creating Subclass in Spyder IPython

Viewed 34

I am on Spyder 4.1.2 with Python 3.7.6, with the following run preference deselected.

Remove all variables before execution

I have 2 separate Python files. The first file starts with:

class Fruit(object):
    def __init__(self, colour):
    ...

The second file starts with:

class Apple(Fruit):
    ...

After running the first file then followed by the second file, I will receive a NameError despite the class Fruit existing after being created in the first file.

NameError: name 'Fruit' is not defined

While I understand I should use the import function, an online course I am currently on had this professor that was able to run the second file without importing the first file.

0 Answers
Related