Skip to content

Instantly share code, notes, and snippets.

@William-Lake
Last active March 7, 2019 17:14
Show Gist options
  • Save William-Lake/94f57b07f7cfaf0afefd7b0b54eb2113 to your computer and use it in GitHub Desktop.
Save William-Lake/94f57b07f7cfaf0afefd7b0b54eb2113 to your computer and use it in GitHub Desktop.
Setting up Windows to use Python Scripts

Setting up Windows to use Python Scripts

  1. Install Python[https://www.python.org/downloads/windows/]

  2. Create a directory to contain your scripts.

  3. Add your created directory to your path.

    1. Start Menu

    2. Type in "environment" and select "Edit Environment variables for your account".

    3. In the upper group titled "User variables for [YOUR NAME]" click the "New…​" button.

    4. Enter your desired variable name (standard is to be in all caps, use underscores instead of spaces, and only letters. E.g. WILLS_PYTHON_SCRIPTS)

    5. Enter the path to your script dir as the Variable Value. Click the "OK" button.

    6. From the upper group titled "User variables for [YOUR NAME]" select the entry whose value in the "Variable" column is "Path". Click "Edit".

    7. From the upper right of the resulting dialog, Click "New".

    8. In the new entry type in the name of the variable you just created, surrounded by percentage marks (E.g. %WILLS_PYTHON_SCRIPTS%)

    9. Click "OK". When the dialog closes, Click "OK" on the parent "Environment Variables" dialog as well.

  4. Add a python script in your created directory. E.g. test.py

  5. Open a new command prompt and type in the name of your test script, E.g. test.py

  6. Add the script below if desired, changing the SCRIPT_DIR_ENV_VAR constant value to reflect the name of your own script dir variable value (E.g. WILLS_PYTHON_SCRIPTS)

list_current_scripts.py
import os
from pathlib import Path

SCRIPT_DIR_ENV_VAR = 'WILLS_PYTHON_SCRIPTS'

SCRIPT_DIR = os.environ[SCRIPT_DIR_ENV_VAR]

if __name__ == "__main__":

    print('\n'.join(os.listdir(SCRIPT_DIR)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment