Cannot import class or function

Hi! So this isn’t so much a Codecademy related question as much as it is a general python question. I recently got into the classes and objects section in python3, and wanted to test out importing classes from a different file on VS Code. But I keep getting this error.
ImportError: cannot import name ‘X_Class’ from ‘my_class’

This is what the code looks like

main.py looks like
from my_class import X_Class

and my_class.py looks like
class X_Class:
pass

The files are in the same directory, and as far as I know there is nothing wrong with the code itself.
Any help would be greatly appreciated as I’m trying to do my own projects, and this has been a bit of a roadblock for me.
Thanks!

Hi,
what you’ve written looks ok, assuming you’ve no pesky spelling errors.
If you’re also importing other things, you may have a ‘circular dependency’.
e.g
file a imports something from file b
but
file b imports something from file a

so, if Python allowed it, you’d get an infinite loop as each file tries to import the other.

hope that helps.

1 Like

Thank you for replying. So far that’s all the code I wrote in these files. I went back and looked, and there doesn’t seem to be any circular dependencies, and if there are some, they’re very hidden.
That’s what’s really confusing me, cause everything seems correct.

I added more to the class besides ‘pass’ and ran it in debug mode. Tut that fixed it!