diff --git a/README.md b/README.md index 6f24294..fccab07 100644 --- a/README.md +++ b/README.md @@ -824,7 +824,9 @@ import . # Imports a built-in or '/.py'. * **Package is a collection of modules, but it can also define its own objects.** * **On a filesystem this corresponds to a directory of Python files with an optional init script.** * **Running `'import '` does not automatically provide access to the package's modules unless they are explicitly imported in its init script.** -* **Imports are relative to the location of file that was passed to python command, but can be made relative to their location with `'from .[…][[.…]] import '`.** +* **Location of the file that is passed to python command serves as a root of all local imports.** +* **For relative imports use `'from .[…][[.…]] import '`.** +* **To install your package go to its parent dir, add 'import setuptools; setuptools.setup()' to setup.py, '[options]' and 'packages = <dir>' to setup.cfg, and run `'pip3 install -e .'`.** Closure @@ -843,9 +845,7 @@ def get_multiplier(a): >>> multiply_by_3(10) 30 ``` - -* **If multiple nested functions within enclosing function reference the same value, that value gets shared.** -* **To dynamically access function's first free variable use `'.__closure__[0].cell_contents'`.** +* **Any value that is referenced from within multiple nested functions gets shared.** ### Partial ```python diff --git a/index.html b/index.html index 884979a..31dc56e 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -693,7 +693,9 @@ player = Player(point, direction) #
  • Package is a collection of modules, but it can also define its own objects.
  • On a filesystem this corresponds to a directory of Python files with an optional init script.
  • Running 'import <package>' does not automatically provide access to the package's modules unless they are explicitly imported in its init script.
  • -
  • Imports are relative to the location of file that was passed to python command, but can be made relative to their location with 'from .[…][<pkg/module>[.…]] import <obj>'.
  • +
  • Location of the file that is passed to python command serves as a root of all local imports.
  • +
  • For relative imports use 'from .[…][<pkg/module>[.…]] import <obj>'.
  • +
  • To install your package go to its parent dir, add 'import setuptools; setuptools.setup()' to setup.py, '[options]' and 'packages = <dir>' to setup.cfg, and run 'pip3 install -e .'.
  • #Closure

    We have/get a closure in Python when a nested function references a value of its enclosing function and then the enclosing function returns the nested function.

    def get_multiplier(a):
         def out(b):
    @@ -707,8 +709,7 @@ player = Player(point, direction)                   #
     30
     
      -
    • If multiple nested functions within enclosing function reference the same value, that value gets shared.
    • -
    • To dynamically access function's first free variable use '<function>.__closure__[0].cell_contents'.
    • +
    • Any value that is referenced from within multiple nested functions gets shared.

    Partial

    from functools import partial
     <function> = partial(<function> [, <arg_1>, <arg_2>, ...])
    @@ -2933,7 +2934,7 @@ $ deactivate                  # Deactivates the activ