Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbf5fdb

Browse files
committed
Introspection, Virtual environments
1 parent 2bb1f54 commit dbf5fdb

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,9 +2184,9 @@ first_element = op.methodcaller('pop', 0)(<list>)
21842184
Introspection
21852185
-------------
21862186
```python
2187-
<list> = dir() # Names of local variables (incl. functions).
2188-
<dict> = vars() # Dict of local variables. Also locals().
2189-
<dict> = globals() # Dict of global variables.
2187+
<list> = dir() # Names of local variables, functions, classes, etc.
2188+
<dict> = vars() # Dict of local variables, etc. Also locals().
2189+
<dict> = globals() # Dict of global vars, etc. (incl. '__builtins__').
21902190
```
21912191

21922192
### Attributes
@@ -3537,15 +3537,16 @@ cdef class <class_name>:
35373537
cdef enum <enum_name>: <member_name>, <member_name>, ...
35383538
```
35393539

3540-
### PyInstaller
3540+
### Virtual Environments
3541+
**System for installing libraries directly into project's directory.**
3542+
35413543
```bash
3542-
$ pip3 install pyinstaller
3543-
$ pyinstaller script.py # Compiles into './dist/script' directory.
3544-
$ pyinstaller script.py --onefile # Compiles into './dist/script' console app.
3545-
$ pyinstaller script.py --windowed # Compiles into './dist/script' windowed app.
3546-
$ pyinstaller script.py --add-data '<path>:.' # Adds file to the root of the executable.
3544+
$ python3 -m venv <name> # Creates virtual environment in current directory.
3545+
$ source <name>/bin/activate # Activates venv. On Windows run `<name>\Scripts\activate`.
3546+
$ pip3 install <library> # Installs the library into active environment.
3547+
$ python3 <path> # Runs the script in active environment. Also `./<path>`.
3548+
$ deactivate # Deactivates virtual environment.
35473549
```
3548-
* **File paths need to be updated to `'os.path.join(sys._MEIPASS, <path>)'`.**
35493550

35503551
### Basic Script Template
35513552
```python

index.html

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<body>
5656
<header>
57-
<aside>July 31, 2023</aside>
57+
<aside>August 1, 2023</aside>
5858
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
5959
</header>
6060

@@ -1805,9 +1805,9 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
18051805
<li><strong>Bitwise operators require objects to have and(), or() and xor() special methods, unlike logical operators that work on all types of objects.</strong></li>
18061806
<li><strong>Also: <code class="python hljs"><span class="hljs-string">'&lt;bool&gt; = &lt;bool&gt; &amp;|^ &lt;bool&gt;'</span></code> and <code class="python hljs"><span class="hljs-string">'&lt;int&gt; = &lt;bool&gt; &amp;|^ &lt;int&gt;'</span></code>.</strong></li>
18071807
</ul>
1808-
<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><pre><code class="python language-python hljs">&lt;list&gt; = dir() <span class="hljs-comment"># Names of local variables (incl. functions).</span>
1809-
&lt;dict&gt; = vars() <span class="hljs-comment"># Dict of local variables. Also locals().</span>
1810-
&lt;dict&gt; = globals() <span class="hljs-comment"># Dict of global variables.</span>
1808+
<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><pre><code class="python language-python hljs">&lt;list&gt; = dir() <span class="hljs-comment"># Names of local variables, functions, classes, etc.</span>
1809+
&lt;dict&gt; = vars() <span class="hljs-comment"># Dict of local variables, etc. Also locals().</span>
1810+
&lt;dict&gt; = globals() <span class="hljs-comment"># Dict of global vars, etc. (incl. '__builtins__').</span>
18111811
</code></pre></div>
18121812

18131813
<div><h3 id="attributes">Attributes</h3><pre><code class="python language-python hljs">&lt;list&gt; = dir(&lt;object&gt;) <span class="hljs-comment"># Names of object's attributes (incl. methods).</span>
@@ -2886,16 +2886,14 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
28862886
</code></pre>
28872887
<pre><code class="python language-python hljs">cdef enum &lt;enum_name&gt;: &lt;member_name&gt;, &lt;member_name&gt;, ...
28882888
</code></pre>
2889-
<div><h3 id="pyinstaller">PyInstaller</h3><pre><code class="bash language-bash hljs">$ pip3 install pyinstaller
2890-
$ pyinstaller script.py <span class="hljs-comment"># Compiles into './dist/script' directory.</span>
2891-
$ pyinstaller script.py --onefile <span class="hljs-comment"># Compiles into './dist/script' console app.</span>
2892-
$ pyinstaller script.py --windowed <span class="hljs-comment"># Compiles into './dist/script' windowed app.</span>
2893-
$ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment"># Adds file to the root of the executable.</span>
2889+
<div><h3 id="virtualenvironments">Virtual Environments</h3><p><strong>System for installing libraries directly into project's directory.</strong></p><pre><code class="bash language-bash hljs">$ python3 -m venv &lt;name&gt; <span class="hljs-comment"># Creates virtual environment in current directory.</span>
2890+
$ <span class="hljs-built_in">source</span> &lt;name&gt;/bin/activate <span class="hljs-comment"># Activates venv. On Windows run `&lt;name&gt;\Scripts\activate`.</span>
2891+
$ pip3 install &lt;library&gt; <span class="hljs-comment"># Installs the library into active environment.</span>
2892+
$ python3 &lt;path&gt; <span class="hljs-comment"># Runs the script in active environment. Also `./&lt;path&gt;`.</span>
2893+
$ deactivate <span class="hljs-comment"># Deactivates virtual environment.</span>
28942894
</code></pre></div>
28952895

2896-
<ul>
2897-
<li><strong>File paths need to be updated to <code class="python hljs"><span class="hljs-string">'os.path.join(sys._MEIPASS, &lt;path&gt;)'</span></code>.</strong></li>
2898-
</ul>
2896+
28992897
<div><h3 id="basicscripttemplate">Basic Script Template</h3><pre><code class="python language-python hljs"><span class="hljs-comment">#!/usr/bin/env python3</span>
29002898
<span class="hljs-comment">#</span>
29012899
<span class="hljs-comment"># Usage: .py</span>
@@ -2932,7 +2930,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29322930

29332931

29342932
<footer>
2935-
<aside>July 31, 2023</aside>
2933+
<aside>August 1, 2023</aside>
29362934
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29372935
</footer>
29382936

0 commit comments

Comments
 (0)