"no such file: main.py" How to organize and import class files on replit
I have not been able to import a class that I have created from a file in my repl. I've been able to import other packages, but not my own classes from files that I have created. this might be a problem related to how to organize the files within a replit project.
How do you set up the class files and the main file in Replit? I've tried it a couple different ways, each time getting "no such file: main.py" In the case of the 0121 Classes test project (mistakenly named 02121 instead of 0421 for today's date), I tried it with main outside of the folder called 0421Classtest and after I dragged main into that folder. Same result of "no such file: main.py ."
When making new Python files, it's
[file name].py. So instead of
triangle, it should be
triangle.py. Same for
polygon. Then, you can just keep
from triangle import *, and it should work.
Good luck! :D
Thank you very much! After I changed the file extensions to .py, the Python logo appeared to the left of the file names and main.py ran!
If I commented out everything related to the Rectangle class, I was able to print the area of the t object (Triangle class), so the class files were imported to main! Nice.
But, I kept getting "name Rectangle is not defined," on line 5 of main.py I attached screenshots. It seems to me that the Rectangle class is properly defined.
@RichardPeskett Hm it seems like everything is defined correctly..not very sure why. Perhaps try instead of
from rectangle import * you could just import the class:
from rectangle import Rectangle.
So yeah sorry, but good luck anyways :)
Try taking the files out of the folder. If that doesn't work, start a new repl and make sure main.py always stays out of the folder.