Table of Contents


Creating profiles in Python

Python supports user profiles which are user generated code saved into a default file location, that the python interpreter or native IDLE shell loads on startup of the shell and runs the code. To get started using a profile, first run the code below to determine the location that python uses to load up the default profile from.

>>> import site
>>> site.getusersitepackages()

Now you can create a file named in that directory and put anything you want in it. It will affect every invocation of Python, unless it is started with the -s option to disable the automatic import. sitecustomize works in the same way, but is typically created by an administrator of the computer in the global site-packages directory, and is imported before usercustomize. See the documentation of the site module for more details.

First find the directory of current
>>>import site

Although the output shows the above file path exists it doesn’t' and needs to be created.

Create the folders down to the subdirectory below using the windows file explorer.
Then create a file in that directory named the os.chdir() method will change the current working directory to the site package folder. And the open() method can be used to create a file.
>>>txt_object = open("usercustomize.p", "w+")

Anything you place in this file will be your startup profile when starting python for the first time through any default shell, IDLE or Interpreter such as PowerShell. Anything with .py extension can be opened with notepad to start typing or you may use the open() method to amend the file from within the shell and add data.

Visit next page to learn about - Theory