Skip to content
← Back to Community
How to Remove the Default File in a Python Repl
Profile icon
EpicRaisin

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.

The Steps

  1. Create the repl if you haven't already.
  2. Type the shown text into the console:
    image

import os

os.remove('main.py')

  1. Done! The file will be completely removed from the repl.
    image

If you run now, you'll get this message:
image

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).

image

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!

Voters
Profile icon
Resgame9915
Profile icon
adsarebbbad
Profile icon
BCP
Profile icon
RedGuy7
Profile icon
TsunamiOrSumth
Profile icon
EpicRaisin
Comments
hotnewtop
Profile icon
CodeLongAndPros

Or even better: ln script.py main.py and bam