Rename Files

epc.py is an ugly filename. Most Flask apps use something like app.py as the entry-point. Let’s ask PyCharm’s Project tool window to help us on the renaming.

Source for this step | View video/audio walkthrough

Steps

  1. In the Project tool, right-click on epc.py.
  2. Choose Refactor -> Rename.
  3. Rename to app.py and click Refactor.
  4. Note the new filename.
  5. In the menu, choose Run -> Edit Configurations.
  6. Note that the Script: field is now pointed at the new name.
  7. Click Cancel to close the dialog.
  8. Reload your browser to confirm the page is still loading.
  9. In the Run tool window at the bottom, it is still pointing to the old name.
  10. Click the green circle arrow to restart with the changed run configuration.
  11. Reload in browser.

Analysis

The Project tool window helps us work with the code in our project. In fact, it can do some of our work for us.

  • Rename Refactoring. PyCharm has “refactorings” which do work for you. The Rename refactoring: changed the file name, renamed it in VCS, and changed the run configuration. As we’ll see later, it can do more.
  • Actions everywhere. The Rename refactoring is an “action” that we used with a right-click in the Project tool. That action is available via right-click in other places (e.g. the editor). But you can get to that action via the PyCharm menu, shortcuts, searching for actions, etc. We’ll see that later in Navigation.

Extra Credit

  1. The web page still worked even though pointed at the old filename. Why?
  2. If you opened the Terminal tool and used the command-line to rename the file, what would happen?