cheat_sheets_python
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cheat_sheets_python [2023/01/05 02:12] – [Files: Reading From] gman | cheat_sheets_python [2023/01/18 01:24] (current) – [Main Block] gman | ||
---|---|---|---|
Line 24: | Line 24: | ||
---- | ---- | ||
+ | ===== Virtual Environment ===== | ||
+ | |||
+ | Create a new virtual environment for // | ||
+ | * This way the dependencies of each project are isolated from the system and from the other projects (avoiding conflicts). | ||
+ | * There are no limits to the number of environments you can have since they are just directories containing a few scripts. | ||
+ | |||
+ | **Installation: | ||
+ | |||
+ | **Create a Virtual Environment: | ||
+ | |||
+ | < | ||
+ | $ mkdir dir_name_whatever | ||
+ | $ cd dir_name_whatever | ||
+ | |||
+ | $ python3 -m venv name_of_venv | ||
+ | # -m : tells python to run the module as a script | ||
+ | # venv : the module we want to run as a script | ||
+ | # name : name it whatever you want | ||
+ | |||
+ | $ source name_of_venv/ | ||
+ | # runs the script to activate your virt env | ||
+ | # your prompt should change: prefixed by name of venv | ||
+ | |||
+ | $ deactivate | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
===== Files: Reading From ===== | ===== Files: Reading From ===== | ||
Line 92: | Line 120: | ||
---- | ---- | ||
- | ===== Check: File Load ===== | + | ===== Main Block ===== |
- | Runs main() if file was not imported: | + | Runs '' |
< | < | ||
Line 101: | Line 129: | ||
</ | </ | ||
- | ---- | + | By including this '' |
+ | | ||
+ | | ||
+ | * Since '' | ||
+ | * This means everything else in your imported program (functions, classes, etc.) is available to you, but the main block will //**not**// be executed. Pretty slick |
cheat_sheets_python.1672884765.txt.gz · Last modified: by gman