From d4c8e004d9632e0f6b00b9021ed8b6c4b3a43d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 30 Dec 2021 23:23:41 +0100 Subject: [PATCH] Datetime, Splat operator --- README.md | 7 +++---- index.html | 15 ++++++++------- pdf/remove_links.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index fea2ede..c732d68 100644 --- a/README.md +++ b/README.md @@ -602,7 +602,7 @@ from dateutil.tz import UTC, tzlocal, gettz, datetime_exists, resolve_imaginary ``` * **Use `'.weekday()'` to get the day of the week (Mon == 0).** * **`'fold=1'` means the second pass in case of time jumping back for one hour.** -* **TD converts and normalizes args to ±days, seconds (< 86 400) and microseconds (< 1M).** +* **Timedelta normalizes arguments to ±days, seconds (< 86 400) and microseconds (< 1M).** ### Now ```python @@ -675,6 +675,8 @@ def f(): # def f(x, y): def f(): # def f(x=0, y=0): def f(, ): # def f(x, y=0): ``` +* **A function has it's default values evaluated when it's first encountered in the scope.** +* **Any changes to mutable objects will persist between invocations.** Splat Operator @@ -706,7 +708,6 @@ def add(*a): #### Legal argument combinations: ```python -def f(x, y, z): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3) def f(*, x, y, z): # f(x=1, y=2, z=3) def f(x, *, y, z): # f(x=1, y=2, z=3) | f(1, y=2, z=3) def f(x, y, *, z): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) @@ -716,13 +717,11 @@ def f(x, y, *, z): # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3 def f(*args): # f(1, 2, 3) def f(x, *args): # f(1, 2, 3) def f(*args, z): # f(1, 2, z=3) -def f(x, *args, z): # f(1, 2, z=3) ``` ```python def f(**kwargs): # f(x=1, y=2, z=3) def f(x, **kwargs): # f(x=1, y=2, z=3) | f(1, y=2, z=3) -def f(*, x, **kwargs): # f(x=1, y=2, z=3) ``` ```python diff --git a/index.html b/index.html index c1f260f..ea13ff0 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -535,7 +535,7 @@ to_exclusive = <range>.stop
  • Use '<D/DT>.weekday()' to get the day of the week (Mon == 0).
  • 'fold=1' means the second pass in case of time jumping back for one hour.
  • -
  • TD converts and normalizes args to ±days, seconds (< 86 400) and microseconds (< 1M).
  • +
  • Timedelta normalizes arguments to ±days, seconds (< 86 400) and microseconds (< 1M).

Now

<D/DTn>  = D/DT.today()                     # Current local date or naive datetime.
 <DTn>    = DT.utcnow()                      # Naive datetime from current UTC time.
@@ -597,6 +597,10 @@ to_exclusive   = <range>.stop
 def f(<nondefault_args>, <default_args>):      # def f(x, y=0):
 
+
    +
  • A function has it's default values evaluated when it's first encountered in the scope.
  • +
  • Any changes to mutable objects will persist between invocations.
  • +

#Splat Operator

Inside Function Call

Splat expands a collection into positional arguments, while splatty-splat expands a dictionary into keyword arguments.

args   = (1, 2)
 kwargs = {'x': 3, 'y': 4, 'z': 5}
 func(*args, **kwargs)
@@ -615,8 +619,7 @@ func(*args, **kwargs)
 
>>> add(1, 2, 3)
 6
 
-

Legal argument combinations:

def f(x, y, z):                # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3)
-def f(*, x, y, z):             # f(x=1, y=2, z=3)
+

Legal argument combinations:

def f(*, x, y, z):             # f(x=1, y=2, z=3)
 def f(x, *, y, z):             # f(x=1, y=2, z=3) | f(1, y=2, z=3)
 def f(x, y, *, z):             # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3)
 
@@ -624,11 +627,9 @@ func(*args, **kwargs)
def f(*args):                  # f(1, 2, 3)
 def f(x, *args):               # f(1, 2, 3)
 def f(*args, z):               # f(1, 2, z=3)
-def f(x, *args, z):            # f(1, 2, z=3)
 
def f(**kwargs):               # f(x=1, y=2, z=3)
 def f(x, **kwargs):            # f(x=1, y=2, z=3) | f(1, y=2, z=3)
-def f(*, x, **kwargs):         # f(x=1, y=2, z=3)
 
def f(*args, **kwargs):        # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3)
 def f(x, *args, **kwargs):     # f(x=1, y=2, z=3) | f(1, y=2, z=3) | f(1, 2, z=3) | f(1, 2, 3)
@@ -2875,7 +2876,7 @@ $ pyinstaller script.py --add-data '<path>:.'  
  
 
   
- +
diff --git a/pdf/remove_links.py b/pdf/remove_links.py index 86f3335..5480a8f 100755 --- a/pdf/remove_links.py +++ b/pdf/remove_links.py @@ -7,7 +7,7 @@ from pathlib import Path MATCHES = { - 'For details about built-in functions sorted(), min() and max() see sortable.': 'For details about built-in functions sorted(), min() and max() see sortable (p. 16).', + 'For details about sorted(), min() and max() see sortable.': 'For details about sorted(), min() and max() see sortable (p. 16).', 'Module operator provides functions itemgetter() and mul() that offer the same functionality as lambda expressions above.': 'Module \'operator\' (p. 31) provides functions itemgetter() and mul() that offer the same functionality as lambda expressions (p. 11) above.', 'Adding \'!r\' before the colon converts object to string by calling its repr() method.': 'Adding \'!r\' before the colon converts object to string by calling its repr() method (p. 14).', 'It can be any callable, but is usually implemented as a function that returns a closure.': 'It can be any callable (p. 17), but is usually implemented as a function that returns a closure (p. 12).',