How to Remove the Default File in a Python Repl
Have you ever made a repl, and thought, 'Hey, why can't I rename the default file? I want it to be called
script.py instead of
main.py? Or maybe you've thought 'Why can't I move the default file to this folder?' Well, this tutorial is for you then.
The default file in a repl cannot be deleted, renamed, or moved. This is probably so the repl knows what file to run by default. If you moved/renamed/deleted the default file, then the repl wouldn't be able to find the file to run, since the file wouldn't exist in the directory aimed for. Therefore, repl.it doesn't allow you to rename, move, or delete the default file. But if you wanted to do these to the default file, there is a way. The way is by removing the default file then adding our own "default" file.
How can you remove it though, if it was clarified that you cannot? Well, there's a little trick you can use to do this.
- Create the repl if you haven't already.
- Type the shown text into the console:
- Done! The file will be completely removed from the repl.
If you run now, you'll get this message:
Now that the default file is deleted, we can add our own 'default' file. Make sure you don't name it
main.py, though, else it'll be counted as the default file and you won't be able to rename or move it. But if you name it something else, you can do all the actions you can do to a regular file. Note: You can name files
main.py without it becoming the default file as long as it is not in the main directory (so in a folder).
If you want the repl to run this new script when you run, then add a file named
.replit to your repl, and add this text, replacing
name.py with what you named your new "default" file:
run = 'python name.py'
Thanks for reading this tutorial! If you have any tricks to remove the default file in other languages, I would love to see them in the comments!
Check out the included repl if you want to see that this actually works!