Can someone explain how folders, files and main.py work?
So I just started coding with Python on repl.it and I'm very confused about how the whole folder and file system works, at first I thought that I'd be able to run specific code in a specific file but this doesn't seem to work. Do I just need to make a new repl everytime? And are folder and files purely there for organizational reasons and not to literally seperate code?
The folder structure on Replit works exactly as it does on a regular computer. There are a variety of reasons why you might want to create different files and folders, especially if you're creating a module. Another use would be to separate different sub-projects that you may have going on under one large project. If you ever decide to get into web development, this would be good for separating server code and client code.
By default, Repls are set up to always run whatever's in main.py. If you want to run code in a different file, you'll have to invoke the
python command yourself in the Bash console. You can also use the .replit file to make the Run button run different files.
@OilyOlive Okay then, I shall explain.
Under normal circumstances, to run a Python script named CoolScript.py in the current directory, you'd run the following command in your console:
Replit automatically calls
python main.py for Python Repls when you hit the run button. However, with the .replit file, you can change this. Say you wanted to run the same script instead of main.py. To do that, you'd put this in the .replit file:
If the script is in a different folder, however, we need to specify that the script is in that folder. If CoolScript.py is in a folder called AwesomeFolder, put this in instead: