You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
***`'{<num>:g}'` is `'{<float>:.6}'` that strips `'.0'` and has exponent starting at `'1e+06'`.**
483
-
***When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. Hence `'{6.5:.0f}'` becomes a `'6'`, while `'{7.5:.0f}'` an `'8'`. This rule only effects numbers that can be represented exactly by a float (`.5`, `.25`, …).**
483
+
***When both rounding up and rounding down are possible, the one that returns result with even last digit is chosen. Hence `'{6.5:.0f}'` becomes a `'6'`, while `'{7.5:.0f}'` an `'8'`.**
484
+
***The last rule only effects numbers that can be represented exactly by a float (`.5`, `.25`, …).**
***Times and datetimes that have defined timezone are called aware and ones that don't, naive. If time or datetime object is naive, it is presumed to be in the system's timezone!**
607
608
***`'fold=1'` means the second pass in case of time jumping back (usually for one hour).**
**Independent block of code that returns a value when called.**
675
+
674
676
```python
675
-
def<func_name>(<nondefault_args>): ...# E.g. `def func(x, y): ...`.
676
-
def<func_name>(<default_args>): ...# E.g. `def func(x=0, y=0): ...`.
677
-
def<func_name>(<nondefault_args>, <default_args>): ...# E.g. `def func(x, y=0): ...`.
677
+
def<func_name>(<nondefault_args>): ...# E.g. `func(x, y):`.
678
+
def<func_name>(<default_args>): ...# E.g. `func(x=0, y=0):`.
679
+
def<func_name>(<nondefault_args>, <default_args>): ...# E.g. `func(x, y=0):`.
678
680
```
679
681
***Function returns None if it doesn't encounter the `'return <object/expr>'` statement.**
680
682
***Run `'global <var_name>'` inside the function before assigning to the global variable.**
@@ -820,13 +822,14 @@ Imports
820
822
**Mechanism that makes code in one file available to another file.**
821
823
822
824
```python
823
-
import<module># Imports a built-in or '<module>.py'.
824
-
import<package># Imports a built-in or '<package>/__init__.py'.
825
-
import<package>.<module># Imports a built-in or '<package>/<module>.py'.
825
+
import<module># Imports a built-in module or the '<module>.py'.
826
+
import<package># A built-in package or '<package>/__init__.py'.
827
+
import<package>.<module># A package's module or '<package>/<module>.py'.
828
+
from<pkg/mod>[.…] import<obj># Imports a module, function, variable or class.
826
829
```
827
-
***Package is a collection of modules, but it can also define its own functions, classes, etc. On a filesystem this corresponds to a directory of Python files with an optional init script.**
828
-
***Running `'import <package>'`does not automatically provide access to the package's modules unless they are explicitly imported in the `'<package>/__init__.py'` script.**
829
-
***Directory of the file that is passed to python command serves as a root of local imports.**
830
+
***Package is a collection of modules, but it can also define its own functions, variables, etc. On a filesystem this corresponds to a directory of Python files with an optional init script.**
831
+
***`'import <package>'`only exposes modules that are imported inside `'__init__.py'`.**
832
+
***Directory of the file that is passed to python command serves as the root of local imports.**
830
833
***Use relative imports, i.e. `'from .[…][<pkg/mod>[.…]] import <obj>'`, if project has scattered entry points. Another option is to install the whole project by moving its code into 'src' dir, adding ['pyproject.toml'](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#basic-information) to its root, and running `'$ pip3 install -e .'`.**
831
834
832
835
@@ -1699,7 +1702,7 @@ import os, shutil
1699
1702
```
1700
1703
1701
1704
```python
1702
-
os.chdir(<path>) # Changes the current working directory (CWD).
1705
+
os.chdir(<path>) # Changes the current working directory (or CWD).
1703
1706
os.mkdir(<path>, mode=0o777) # Creates a directory. Permissions are in octal.
1704
1707
os.makedirs(<path>, mode=0o777) # Creates all path's dirs. Also `exist_ok=False`.
1705
1708
```
@@ -2099,14 +2102,14 @@ import operator as op
2099
2102
```
2100
2103
2101
2104
```python
2102
-
<bool>= op.not_(<obj>) # or, and, not (or/and missing)
2103
-
<bool>= op.eq/ne/lt/ge/is_/is_not/contains(<obj>, <obj>) # ==, !=, <, >=, is, is not, in
2104
-
<obj>= op.or_/xor/and_(<int/set>, <int/set>) # |, ^, & (sorted by precedence)
***An object with `'filter(<LogRecord>)'` method (or the method itself) can be added to loggers and handlers via addFilter(). Message is dropped if filter() returns a false value.**
2202
2205
***Logging messages generated by libraries are passed to the root's handlers. Level of the library's logger can be set with `'log.getLogger("<library>").setLevel(<str>)'`.**
2203
2206
2204
-
#### Creates a logger that writes all messages to a file and sends them to the root's handler that prints warnings or higher:
2207
+
#### Logger that writes messages to file and sends them to the root's handler that prints warnings or higher:
0 commit comments