From 00b3d806f03150f765db2e6995d8acd170caa979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 5 Mar 2019 19:36:34 +0100 Subject: [PATCH 0001/1836] Json, Numpy --- README.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a8817f61d..98d33fb3c 100644 --- a/README.md +++ b/README.md @@ -1136,12 +1136,6 @@ import json = json.loads() ``` -#### To preserve order use: -```python -from collections import OrderedDict - = json.loads(, object_pairs_hook=OrderedDict) -``` - ### Read Object from JSON File ```python def read_json_file(filename): @@ -1762,8 +1756,8 @@ import numpy as np ``` ```python - = .sum(axis=None) -indexes = .argmin(axis=None) + = .sum(axis) +indexes = .argmin(axis) ``` * **Shape is a tuple of dimension sizes.** From 8e1629550499b9c1c48ef5ab50b83a59748eb45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 7 Mar 2019 00:15:59 +0100 Subject: [PATCH 0002/1836] Minor fixes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 98d33fb3c..d9371fcce 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ for i, el in enumerate( [, i_start]): Named Tuple ----------- * **Tuple is an immutable and hashable list.** -* **Named tuple is its subclass with named elements.** +* **Named tuple is it's subclass with named elements.** ```python >>> from collections import namedtuple @@ -1744,7 +1744,7 @@ import numpy as np ```python = np.array() - = np.arange(from_inclusive, to_exclusive, step_size) + = np.arange(from_inclusive, to_exclusive, ±step_size) = np.ones() = np.random.randint(from_inclusive, to_exclusive, ) ``` From 5be679ae82d210af13087c4f224d101556f0ec11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 7 Mar 2019 01:13:02 +0100 Subject: [PATCH 0003/1836] Grammar --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d9371fcce..4b739b8ad 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ for i, el in enumerate( [, i_start]): Named Tuple ----------- * **Tuple is an immutable and hashable list.** -* **Named tuple is it's subclass with named elements.** +* **Named tuple is its subclass with named elements.** ```python >>> from collections import namedtuple @@ -290,7 +290,7 @@ import re * **Parameter `'flags=re.IGNORECASE'` can be used with all functions.** * **Parameter `'flags=re.DOTALL'` makes dot also accept newline.** -* **Use `r'\1'` or `'\\\\1'` for backreference.** +* **Use `r'\1'` or `'\\1'` for backreference.** * **Use `'?'` to make operator non-greedy.** ### Match Object @@ -303,7 +303,7 @@ import re ``` ### Special Sequences -**Expressions below hold true for strings that contain only ASCII characters. Use capital letter for negation.** +**Expressions below hold true for strings that contain only ASCII characters. Use capital letters for negation.** ```python '\d' == '[0-9]' # Digit '\s' == '[ \t\n\r\f\v]' # Whitespace @@ -486,7 +486,7 @@ def f(, ): # def f(x, y=0) Splat Operator -------------- ### Inside Function Call -**Splat expands collection into positional arguments, while splatty-splat expands dictionary into keyword arguments.** +**Splat expands a collection into positional arguments, while splatty-splat expands a dictionary into keyword arguments.** ```python args = (1, 2) kwargs = {'x': 3, 'y': 4, 'z': 5} @@ -499,7 +499,7 @@ func(1, 2, x=3, y=4, z=5) ``` ### Inside Function Definition -**Splat combines zero or more positional arguments into tuple, while splatty-splat combines zero or more keyword arguments into dictionary.** +**Splat combines zero or more positional arguments into a tuple, while splatty-splat combines zero or more keyword arguments into a dictionary.** ```python def add(*a): return sum(a) @@ -784,7 +784,7 @@ class MyComparable: ``` ### Hashable -* **Hashable object needs both hash() and eq() methods and it's hash value should never change.** +* **Hashable object needs both hash() and eq() methods and its hash value should never change.** * **Hashable objects that compare equal must have the same hash value, meaning default hash() that returns `'id(self)'` will not do.** * **That is why Python automatically makes classes unhashable if you only implement eq().** @@ -1200,7 +1200,7 @@ db.commit() Bytes ----- -**Bytes object is immutable sequence of single bytes. Mutable version is called 'bytearray'.** +**Bytes object is an immutable sequence of single bytes. Mutable version is called 'bytearray'.** ```python = b'' @@ -1374,7 +1374,7 @@ Metaprograming **Code that generates code.** ### Type -**Type is the root class. If only passed the object it returns it's type (class). Otherwise it creates a new class.** +**Type is the root class. If only passed the object it returns its type (class). Otherwise it creates a new class.** ```python = type(, , ) From e36fecff3fbbc6f8fba39be215c202772a36f54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 7 Mar 2019 23:22:41 +0100 Subject: [PATCH 0004/1836] String --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b739b8ad..48e00c382 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ String ```python = .split() # Splits on any whitespace character. = .split(sep=None, maxsplit=-1) # Splits on 'sep' str at most 'maxsplit' times. - = .join() # Joins elements using string as separator. + = .join() # Joins string elements using str as separator. ``` ```python From cfe6b41b336f4469c50508f568facdad8035e735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 7 Mar 2019 23:27:50 +0100 Subject: [PATCH 0005/1836] String --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48e00c382..4b739b8ad 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ String ```python = .split() # Splits on any whitespace character. = .split(sep=None, maxsplit=-1) # Splits on 'sep' str at most 'maxsplit' times. - = .join() # Joins string elements using str as separator. + = .join() # Joins elements using string as separator. ``` ```python From 72fbd93be86ff3468c28d5f3658524a6bfb4aa48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 7 Mar 2019 23:29:33 +0100 Subject: [PATCH 0006/1836] String --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b739b8ad..a061b3e8d 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ String ```python = .split() # Splits on any whitespace character. = .split(sep=None, maxsplit=-1) # Splits on 'sep' str at most 'maxsplit' times. - = .join() # Joins elements using string as separator. + = .join() # Joins elements using string as separator. ``` ```python From 6638c9e9422f372052859f035a2058e8df77b3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 8 Mar 2019 13:01:59 +0100 Subject: [PATCH 0007/1836] Curses --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index a061b3e8d..c8f65397c 100644 --- a/README.md +++ b/README.md @@ -1583,7 +1583,6 @@ with open(, encoding='utf-8') as file: Curses ------ ```python -# $ pip3 install curses from curses import wrapper def main(): From d4d979eebb4110d06674e4ab1f0704cb1afb763c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 00:53:02 +0100 Subject: [PATCH 0008/1836] Datetime overhaul --- README.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c8f65397c..1b11e6e5b 100644 --- a/README.md +++ b/README.md @@ -456,13 +456,76 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- +* **Module Datetime provides Date (`''`), Time (`''`) and Datetime (`'
'`) classes.** +* **Time and Datetime can be 'aware' (`''`), meaning they have defined timezone, or 'naive' (`''`), meaning they don't. + ```python -from datetime import datetime -now = datetime.now() -now.month # 3 -now.strftime('%Y%m%d') # '20180315' -now.strftime('%Y%m%d%H%M%S') # '20180315002834' - = datetime.strptime('2015-05-12 00:39', '%Y-%m-%d %H:%M') +$ pip3 install pytz +from datetime import date, time, datetime, timedelta +import pytz +``` + +### Constructors +```python + = date(year, month, day) + = time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) +
= datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) + = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) +``` +* **`'fold=1'` means second pass in case of time jumping back for one hour.** +* **Use `'.weekday()'` to get day of the week (Mon == 0). + +### Now +```python + = date.today() # Current local date. + = datetime.today() # Naive datetime from current local time. + = datetime.utcnow() # Naive datetime from current UTC time. + = datetime.now() # Aware datetime from current time. +``` + +### Encode +```python + = D/T/DT.fromisoformat() # From 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both. +
= DT.strptime(, '') # Datetime from string according to 'format'. + = D/DT.fromordinal() # Date or datetime from days since Christ. + = D/DT.fromtimestamp() # Date or datetime from seconds since Epoch in local time. + = DT.utcfromtimestamp() # Naive datetime from seconds since Epoch in UTC time. + = DT.fromtimestamp(, ) # Aware datetime from seconds since Epoch in time. +``` +* **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** + +### Decode +```python + = .isoformat() # 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both. + = .strftime('') # Returns customized string representation. + = .toordinal() # Returns days since Christ ignoring time and timezone. + =
.timestamp() # Returns seconds since Epoch in local time or if set. +``` + +### Format +```python +>>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') +``` + +#### Rest of the options: +* **`'y'` - Year, 2 digits** +* **`'b'` - Month, abbreviated name** +* **`'B'` - Month, full name** +* **`'a'` - Weekday, abbreviated name** +* **`'A'` - Weekday, full name** +* **`'I'` - Hours, 2 digits, 12 hours** +* **`'p'` - AM/PM** +* **`'f'` - Microseconds, 6 digits** +* **`'z'` - Timezone offset, ± and 4 digits** +* **`'Z'` - Timezone name** + +### Timezone +```python + = pytz.timezone('/') # Use 'pytz.utc' for UTC. + =
.astimezone() # Converts datetime to passed timezone. + = .replace(tzinfo=) # Changes timezone without conversion. + = .utcoffset() # Returns timezone's current offset from UTC. + = .dst() # Returns daylight saving time offset. ``` From 6bed9731b35058b1c789f61d996733415c0c6d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 00:54:38 +0100 Subject: [PATCH 0009/1836] Datetime fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1b11e6e5b..ebc577adb 100644 --- a/README.md +++ b/README.md @@ -457,7 +457,7 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- * **Module Datetime provides Date (`''`), Time (`''`) and Datetime (`'
'`) classes.** -* **Time and Datetime can be 'aware' (`''`), meaning they have defined timezone, or 'naive' (`''`), meaning they don't. +* **Time and Datetime can be 'aware' (`''`), meaning they have defined timezone, or 'naive' (`''`), meaning they don't.** ```python $ pip3 install pytz @@ -473,7 +473,7 @@ import pytz = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) ``` * **`'fold=1'` means second pass in case of time jumping back for one hour.** -* **Use `'.weekday()'` to get day of the week (Mon == 0). +* **Use `'.weekday()'` to get day of the week (Mon == 0).** ### Now ```python From a3252b4ca052aa1b463868f923305c61e50b18a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 00:55:35 +0100 Subject: [PATCH 0010/1836] Datetime fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ebc577adb..b97a8165c 100644 --- a/README.md +++ b/README.md @@ -456,8 +456,8 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- -* **Module Datetime provides Date (`''`), Time (`''`) and Datetime (`'
'`) classes.** -* **Time and Datetime can be 'aware' (`''`), meaning they have defined timezone, or 'naive' (`''`), meaning they don't.** +* **Module Datetime provides Date (``), Time (``) and Datetime (`
`) classes.** +* **Time and Datetime can be 'aware' (``), meaning they have defined timezone, or 'naive' (``), meaning they don't.** ```python $ pip3 install pytz From f3621eb743c8fc29b97a709b1894618adb21d8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 00:56:01 +0100 Subject: [PATCH 0011/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b97a8165c..e41a42faa 100644 --- a/README.md +++ b/README.md @@ -460,7 +460,7 @@ Datetime * **Time and Datetime can be 'aware' (``), meaning they have defined timezone, or 'naive' (``), meaning they don't.** ```python -$ pip3 install pytz +# $ pip3 install pytz from datetime import date, time, datetime, timedelta import pytz ``` From b88dbb30fe26fae3b029a62c15e33c2257045d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 00:58:22 +0100 Subject: [PATCH 0012/1836] Datetime fix --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e41a42faa..e07aca041 100644 --- a/README.md +++ b/README.md @@ -467,10 +467,10 @@ import pytz ### Constructors ```python - = date(year, month, day) - = time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) -
= datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) - = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) + = date(year, month, day) +
`) classes.** -* **Time and Datetime can be 'aware' (``), meaning they have defined timezone, or 'naive' (``), meaning they don't.** +* **Module Datetime provides 'date' ``, 'time' `` and 'datetime' `
` classes.** +* **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't.** ```python # $ pip3 install pytz @@ -467,10 +467,10 @@ import pytz ### Constructors ```python - = date(year, month, day) -
= datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) + = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) ``` * **`'fold=1'` means second pass in case of time jumping back for one hour.** * **Use `'.weekday()'` to get day of the week (Mon == 0).** From 83fad477231327df6d048c70b4296e4e279e4d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:01:56 +0100 Subject: [PATCH 0014/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e05949b9..c0866d65b 100644 --- a/README.md +++ b/README.md @@ -456,7 +456,7 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- -* **Module Datetime provides 'date' ``, 'time' `` and 'datetime' `
` classes.** +* **Module 'datetime' provides 'date' ``, 'time' `` and 'datetime' `
` classes.** * **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't.** ```python From 2f31a96a2742001a3e4e94c23e8d2870ff118206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:04:08 +0100 Subject: [PATCH 0015/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c0866d65b..32eef4540 100644 --- a/README.md +++ b/README.md @@ -456,7 +456,7 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- -* **Module 'datetime' provides 'date' ``, 'time' `` and 'datetime' `
` classes.** +* **Module 'datetime' provides 'date' ``, 'time' ``, 'datetime' `
` and 'timedelta' `` classes.** * **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't.** ```python From 180ab874731db52d7a5e1bd5e34e4e9f023f1547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:08:12 +0100 Subject: [PATCH 0016/1836] Datetime fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 32eef4540..cb888511c 100644 --- a/README.md +++ b/README.md @@ -472,8 +472,8 @@ import pytz
= datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) ``` -* **`'fold=1'` means second pass in case of time jumping back for one hour.** * **Use `'.weekday()'` to get day of the week (Mon == 0).** +* **`'fold=1'` means second pass in case of time jumping back for one hour.** ### Now ```python @@ -486,7 +486,7 @@ import pytz ### Encode ```python = D/T/DT.fromisoformat() # From 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both. -
= DT.strptime(, '') # Datetime from string according to 'format'. +
= DT.strptime(, '') # Datetime from string according to . = D/DT.fromordinal() # Date or datetime from days since Christ. = D/DT.fromtimestamp() # Date or datetime from seconds since Epoch in local time. = DT.utcfromtimestamp() # Naive datetime from seconds since Epoch in UTC time. From 6ce839b90a8d4bc028bd88807b3b41a4d1626581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:11:48 +0100 Subject: [PATCH 0017/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb888511c..633f3e77f 100644 --- a/README.md +++ b/README.md @@ -484,7 +484,7 @@ import pytz ``` ### Encode -```python +```python = D/T/DT.fromisoformat() # From 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both.
= DT.strptime(, '') # Datetime from string according to . = D/DT.fromordinal() # Date or datetime from days since Christ. From a51055ef866a1214a310f6e1371ab6af78325576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:17:06 +0100 Subject: [PATCH 0018/1836] Datetime fix --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 633f3e77f..5bce24d1e 100644 --- a/README.md +++ b/README.md @@ -465,14 +465,13 @@ from datetime import date, time, datetime, timedelta import pytz ``` -### Constructors ```python = date(year, month, day) = time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0)
= datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) ``` -* **Use `'.weekday()'` to get day of the week (Mon == 0).** +* **Use `'.weekday()'` to get the day of the week (Mon == 0).** * **`'fold=1'` means second pass in case of time jumping back for one hour.** ### Now From ddc89607c29cabd19b1770a1722a47fb6c904f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:19:45 +0100 Subject: [PATCH 0019/1836] Datetime fix --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5bce24d1e..2a9888d7e 100644 --- a/README.md +++ b/README.md @@ -476,10 +476,10 @@ import pytz ### Now ```python - = date.today() # Current local date. - = datetime.today() # Naive datetime from current local time. - = datetime.utcnow() # Naive datetime from current UTC time. - = datetime.now() # Aware datetime from current time. + = D.today() # Current local date. + = DT.today() # Naive datetime from current local time. + = DT.utcnow() # Naive datetime from current UTC time. + = DT.now() # Aware datetime from current time. ``` ### Encode From f253fd1c8989f8bfe99561efb02b8ff87767552a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:20:37 +0100 Subject: [PATCH 0020/1836] Datetime fix --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2a9888d7e..bb02761fd 100644 --- a/README.md +++ b/README.md @@ -465,6 +465,7 @@ from datetime import date, time, datetime, timedelta import pytz ``` +### Constructors ```python = date(year, month, day) = time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) From 335e35a2174a0cc9eff3e45bf27cc669f14038c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:25:45 +0100 Subject: [PATCH 0021/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bb02761fd..3d30cc294 100644 --- a/README.md +++ b/README.md @@ -499,7 +499,7 @@ import pytz = .isoformat() # 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both. = .strftime('') # Returns customized string representation. = .toordinal() # Returns days since Christ ignoring time and timezone. - =
.timestamp() # Returns seconds since Epoch in local time or if set. + =
.timestamp() # Returns seconds since Epoch in local time or tz if set. ``` ### Format From d66e682f8a11bae67f78bbfafb002ee3620790f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:27:03 +0100 Subject: [PATCH 0022/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d30cc294..8e3b58ff5 100644 --- a/README.md +++ b/README.md @@ -507,7 +507,7 @@ import pytz >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') ``` -#### Rest of the options: +#### Rest of the codes: * **`'y'` - Year, 2 digits** * **`'b'` - Month, abbreviated name** * **`'B'` - Month, full name** From 29fd381689826de065884d1cd7e16ab50557b50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:29:49 +0100 Subject: [PATCH 0023/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e3b58ff5..0cd944364 100644 --- a/README.md +++ b/README.md @@ -523,7 +523,7 @@ import pytz ```python = pytz.timezone('/') # Use 'pytz.utc' for UTC. =
.astimezone() # Converts datetime to passed timezone. - = .replace(tzinfo=) # Changes timezone without conversion. + = .replace(tzinfo=) # Changes timezone without conversion. = .utcoffset() # Returns timezone's current offset from UTC. = .dst() # Returns daylight saving time offset. ``` From 5c743570ee27fd1809a36b581b1cfc7e9f90e260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:45:03 +0100 Subject: [PATCH 0024/1836] Datetime fix --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0cd944364..8e351c353 100644 --- a/README.md +++ b/README.md @@ -456,8 +456,9 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- -* **Module 'datetime' provides 'date' ``, 'time' ``, 'datetime' `
` and 'timedelta' `` classes.** -* **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't.** +* **Module 'datetime' provides 'date' ``, 'time' ``, 'datetime' `
` and 'timedelta' `` classes, all of which are immutable and hashable.** +* **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't. +* **If object is naive it is presumed to be in system's timezone.** ```python # $ pip3 install pytz @@ -483,6 +484,15 @@ import pytz = DT.now() # Aware datetime from current time. ``` +### Timezone +```python + = pytz.timezone('/') # Use 'pytz.utc' for UTC. + =
.astimezone() # Converts datetime to passed timezone. + = .replace(tzinfo=) # Changes timezone without conversion. + = .utcoffset() # Returns timezone's current offset from UTC. + = .dst() # Returns daylight saving time offset. +``` + ### Encode ```python = D/T/DT.fromisoformat() # From 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both. @@ -519,15 +529,6 @@ import pytz * **`'z'` - Timezone offset, ± and 4 digits** * **`'Z'` - Timezone name** -### Timezone -```python - = pytz.timezone('/') # Use 'pytz.utc' for UTC. - =
.astimezone() # Converts datetime to passed timezone. - = .replace(tzinfo=) # Changes timezone without conversion. - = .utcoffset() # Returns timezone's current offset from UTC. - = .dst() # Returns daylight saving time offset. -``` - Arguments --------- From 683d439a68c4b19a98a061101ac1d8415a32c27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 01:45:53 +0100 Subject: [PATCH 0025/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e351c353..7d602e7a7 100644 --- a/README.md +++ b/README.md @@ -457,7 +457,7 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- * **Module 'datetime' provides 'date' ``, 'time' ``, 'datetime' `
` and 'timedelta' `` classes, all of which are immutable and hashable.** -* **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't. +* **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't.** * **If object is naive it is presumed to be in system's timezone.** ```python From 491c9271eadedc521fa9f6bac2d44bfc3280129a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:01:22 +0100 Subject: [PATCH 0026/1836] Datetime fix --- README.md | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 7d602e7a7..339f4a762 100644 --- a/README.md +++ b/README.md @@ -495,23 +495,35 @@ import pytz ### Encode ```python - = D/T/DT.fromisoformat() # From 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both. -
= DT.strptime(, '') # Datetime from string according to . + = D/T/DT.fromisoformat() # From 'YYYY-MM-DD' / 'HH:MM:SS.ffffff[+]'. +
= DT.strptime(, '') # Datetime from string according to format. = D/DT.fromordinal() # Date or datetime from days since Christ. - = D/DT.fromtimestamp() # Date or datetime from seconds since Epoch in local time. - = DT.utcfromtimestamp() # Naive datetime from seconds since Epoch in UTC time. - = DT.fromtimestamp(, ) # Aware datetime from seconds since Epoch in time. + = D/DT.fromtimestamp() # D/DT from seconds since Epoch in local time. + = DT.utcfromtimestamp() # Naive DT from seconds since Epoch in UTC time. + = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** ### Decode ```python - = .isoformat() # 'YYYY-MM-DD', 'HH:MM:SS.ffffff[+]' or both. - = .strftime('') # Returns customized string representation. - = .toordinal() # Returns days since Christ ignoring time and timezone. - =
.timestamp() # Returns seconds since Epoch in local time or tz if set. + = .isoformat() # 'YYYY-MM-DD' / 'HH:MM:SS.ffffff[+]'. + = .strftime('') # Customized string representation. + = .toordinal() # Days since Christ, ignoring time and timezone. + =
.timestamp() # Seconds since Epoch in local time or tz if set. ``` +### ISO Format +```python +date == 'YYYY-MM-DD' +time == 'HH:MM:SS.ffffff[+]' +datetime == 'YYYY-MM-DDTHH:MM:SS.ffffff[+]' +``` + +* **Date: `'YYYY-MM-DD'`.** +* **Time: `'HH:MM:SS.ffffff[+]'`.** +* **Datetime: `'YYYY-MM-DDTHH:MM:SS.ffffff[+]'`.** + + ### Format ```python >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') From 96f8f69152dd77e1e43755e6e316f2506b9ac01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:10:50 +0100 Subject: [PATCH 0027/1836] Datetime fix --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 339f4a762..c21d5a17c 100644 --- a/README.md +++ b/README.md @@ -495,7 +495,7 @@ import pytz ### Encode ```python - = D/T/DT.fromisoformat() # From 'YYYY-MM-DD' / 'HH:MM:SS.ffffff[+]'. + = D/T/DT.fromisoformat('') # D/T/DT from ISO string.
= DT.strptime(, '') # Datetime from string according to format. = D/DT.fromordinal() # Date or datetime from days since Christ. = D/DT.fromtimestamp() # D/DT from seconds since Epoch in local time. @@ -506,19 +506,13 @@ import pytz ### Decode ```python - = .isoformat() # 'YYYY-MM-DD' / 'HH:MM:SS.ffffff[+]'. + = .isoformat() # ISO string representation. = .strftime('') # Customized string representation. = .toordinal() # Days since Christ, ignoring time and timezone. =
.timestamp() # Seconds since Epoch in local time or tz if set. ``` -### ISO Format -```python -date == 'YYYY-MM-DD' -time == 'HH:MM:SS.ffffff[+]' -datetime == 'YYYY-MM-DDTHH:MM:SS.ffffff[+]' -``` - +### ISO Formats * **Date: `'YYYY-MM-DD'`.** * **Time: `'HH:MM:SS.ffffff[+]'`.** * **Datetime: `'YYYY-MM-DDTHH:MM:SS.ffffff[+]'`.** From bca5b0b269cbd890d53cf9df374e282caf741c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:16:20 +0100 Subject: [PATCH 0028/1836] Datetime fix --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c21d5a17c..70ac71555 100644 --- a/README.md +++ b/README.md @@ -507,23 +507,22 @@ import pytz ### Decode ```python = .isoformat() # ISO string representation. - = .strftime('') # Customized string representation. + = .strftime('') # Custom string representation. = .toordinal() # Days since Christ, ignoring time and timezone. =
.timestamp() # Seconds since Epoch in local time or tz if set. ``` -### ISO Formats +### Format +#### ISO: * **Date: `'YYYY-MM-DD'`.** * **Time: `'HH:MM:SS.ffffff[+]'`.** * **Datetime: `'YYYY-MM-DDTHH:MM:SS.ffffff[+]'`.** - -### Format +#### Strptime, strftime: ```python >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') ``` -#### Rest of the codes: * **`'y'` - Year, 2 digits** * **`'b'` - Month, abbreviated name** * **`'B'` - Month, full name** From 42fe6ff4fdc6b5162a6b2bcbc19448fa3b57d501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:18:33 +0100 Subject: [PATCH 0029/1836] Datetime fix --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 70ac71555..aa0a3ae57 100644 --- a/README.md +++ b/README.md @@ -512,17 +512,15 @@ import pytz =
.timestamp() # Seconds since Epoch in local time or tz if set. ``` -### Format -#### ISO: +### ISO * **Date: `'YYYY-MM-DD'`.** * **Time: `'HH:MM:SS.ffffff[+]'`.** * **Datetime: `'YYYY-MM-DDTHH:MM:SS.ffffff[+]'`.** -#### Strptime, strftime: +### Format ```python >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') ``` - * **`'y'` - Year, 2 digits** * **`'b'` - Month, abbreviated name** * **`'B'` - Month, full name** From 5a6562ca8f03d6e2c16f266708ab94313a418004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:18:55 +0100 Subject: [PATCH 0030/1836] Datetime fix --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aa0a3ae57..907426320 100644 --- a/README.md +++ b/README.md @@ -513,9 +513,9 @@ import pytz ``` ### ISO -* **Date: `'YYYY-MM-DD'`.** -* **Time: `'HH:MM:SS.ffffff[+]'`.** -* **Datetime: `'YYYY-MM-DDTHH:MM:SS.ffffff[+]'`.** +* **Date: `'YYYY-MM-DD'`** +* **Time: `'HH:MM:SS.ffffff[+]'`** +* **Datetime: `'YYYY-MM-DDTHH:MM:SS.ffffff[+]'`** ### Format ```python From e4f8edce991ce9ee436bce0e1cf81bb6c9c07066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:19:33 +0100 Subject: [PATCH 0031/1836] Datetime fix --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 907426320..526edb9e0 100644 --- a/README.md +++ b/README.md @@ -521,6 +521,8 @@ import pytz ```python >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') ``` + +#### Rest of the options: * **`'y'` - Year, 2 digits** * **`'b'` - Month, abbreviated name** * **`'B'` - Month, full name** From bc7441b7178d493c6f6f5d77003f750de3208144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:20:49 +0100 Subject: [PATCH 0032/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 526edb9e0..967b4a298 100644 --- a/README.md +++ b/README.md @@ -522,7 +522,7 @@ import pytz >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') ``` -#### Rest of the options: +#### Rest of the codes: * **`'y'` - Year, 2 digits** * **`'b'` - Month, abbreviated name** * **`'B'` - Month, full name** From eae41b5801ccfc29de8bb71aed7a7ac18494ab48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:24:17 +0100 Subject: [PATCH 0033/1836] Datetime fix --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 967b4a298..9c327fd85 100644 --- a/README.md +++ b/README.md @@ -503,6 +503,7 @@ import pytz = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** +* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[+]'` or both separated by `'T'`. ### Decode ```python @@ -512,11 +513,6 @@ import pytz =
.timestamp() # Seconds since Epoch in local time or tz if set. ``` -### ISO -* **Date: `'YYYY-MM-DD'`** -* **Time: `'HH:MM:SS.ffffff[+]'`** -* **Datetime: `'YYYY-MM-DDTHH:MM:SS.ffffff[+]'`** - ### Format ```python >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') From aa353265a5373d98d87fc1283bb324890356f3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:24:37 +0100 Subject: [PATCH 0034/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c327fd85..720e9275b 100644 --- a/README.md +++ b/README.md @@ -503,7 +503,7 @@ import pytz = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** -* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[+]'` or both separated by `'T'`. +* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[+]'` or both separated by `'T'`.** ### Decode ```python From 84bc1e780c40a613d5087fbe69bc818ba5366b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:26:56 +0100 Subject: [PATCH 0035/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 720e9275b..c2bbaa9cd 100644 --- a/README.md +++ b/README.md @@ -503,7 +503,7 @@ import pytz = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** -* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[+]'` or both separated by `'T'`.** +* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[+]'`, or both separated by `'T'`.** ### Decode ```python From eaed4429f85787dcade7253e9b010ec062718db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:30:42 +0100 Subject: [PATCH 0036/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2bbaa9cd..c22314b2e 100644 --- a/README.md +++ b/README.md @@ -456,7 +456,7 @@ from itertools import product, combinations, combinations_with_replacement, perm Datetime -------- -* **Module 'datetime' provides 'date' ``, 'time' ``, 'datetime' `
` and 'timedelta' `` classes, all of which are immutable and hashable.** +* **Module 'datetime' provides 'date' ``, 'time' ``, 'datetime' `
` and 'timedelta' `` classes. All are immutable and hashable.** * **Time and datetime can be 'aware' ``, meaning they have defined timezone, or 'naive' ``, meaning they don't.** * **If object is naive it is presumed to be in system's timezone.** From 65ac2fce2f8704298091798f06be6369086a6f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:38:14 +0100 Subject: [PATCH 0037/1836] Datetime fix --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c22314b2e..3aa06cf93 100644 --- a/README.md +++ b/README.md @@ -470,8 +470,9 @@ import pytz ```python = date(year, month, day) = time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) -
= datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0) - = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) +
= datetime(year, month, day, hour=0, minute=0, second=0, ...) + = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, + minutes=0, hours=0, weeks=0) ``` * **Use `'.weekday()'` to get the day of the week (Mon == 0).** * **`'fold=1'` means second pass in case of time jumping back for one hour.** From eb122ffcaec3c2c94cf7cbe7c85af9d4c3ef6e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:43:22 +0100 Subject: [PATCH 0038/1836] Datetime fix --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3aa06cf93..035c25f3d 100644 --- a/README.md +++ b/README.md @@ -487,7 +487,8 @@ import pytz ### Timezone ```python - = pytz.timezone('/') # Use 'pytz.utc' for UTC. + = pytz.utc # UTC timezone. + = pytz.timezone('/') # Timezone from 'Continent/City' string. =
.astimezone() # Converts datetime to passed timezone. = .replace(tzinfo=) # Changes timezone without conversion. = .utcoffset() # Returns timezone's current offset from UTC. From 6a5a76fca9c8a49722c333196feafe7be9c357be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 02:59:51 +0100 Subject: [PATCH 0039/1836] Datetime fix --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 035c25f3d..52ef8bc4c 100644 --- a/README.md +++ b/README.md @@ -489,10 +489,10 @@ import pytz ```python = pytz.utc # UTC timezone. = pytz.timezone('/') # Timezone from 'Continent/City' string. - =
.astimezone() # Converts datetime to passed timezone. - = .replace(tzinfo=) # Changes timezone without conversion. - = .utcoffset() # Returns timezone's current offset from UTC. - = .dst() # Returns daylight saving time offset. + =
.astimezone() # Datetime converted to passed timezone. + = .replace(tzinfo=) # Unconverted object with new timezone. + = .utcoffset() # Timezone's current offset from UTC. + = .dst() # Daylight saving time offset. ``` ### Encode From bd8099f0dbf88866cdadd2f9cf34eeaa4513276b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:04:23 +0100 Subject: [PATCH 0040/1836] Datetime fix --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 52ef8bc4c..387cb1cbe 100644 --- a/README.md +++ b/README.md @@ -491,8 +491,6 @@ import pytz = pytz.timezone('/') # Timezone from 'Continent/City' string. =
.astimezone() # Datetime converted to passed timezone. = .replace(tzinfo=) # Unconverted object with new timezone. - = .utcoffset() # Timezone's current offset from UTC. - = .dst() # Daylight saving time offset. ``` ### Encode From 41c1c48d185021b758085a5d77fda70075b3ffa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:08:27 +0100 Subject: [PATCH 0041/1836] Datetime fix --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 387cb1cbe..6aa05953d 100644 --- a/README.md +++ b/README.md @@ -479,10 +479,9 @@ import pytz ### Now ```python - = D.today() # Current local date. - = DT.today() # Naive datetime from current local time. + = D/DT.today() # Current local date or naive datetime. = DT.utcnow() # Naive datetime from current UTC time. - = DT.now() # Aware datetime from current time. + = DT.now() # Aware datetime from current tz time. ``` ### Timezone From 489de09fbf59640c945527ab548cda945daeaa31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:10:03 +0100 Subject: [PATCH 0042/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6aa05953d..5d10cd9f0 100644 --- a/README.md +++ b/README.md @@ -488,7 +488,7 @@ import pytz ```python = pytz.utc # UTC timezone. = pytz.timezone('/') # Timezone from 'Continent/City' string. - =
.astimezone() # Datetime converted to passed timezone. + =
.astimezone() # Datetime, converted to passed timezone. = .replace(tzinfo=) # Unconverted object with new timezone. ``` From c6bc792d8dca09700f385c25ff3c9a22ffdb4476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:13:32 +0100 Subject: [PATCH 0043/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d10cd9f0..cf214fcee 100644 --- a/README.md +++ b/README.md @@ -494,7 +494,7 @@ import pytz ### Encode ```python - = D/T/DT.fromisoformat('') # D/T/DT from ISO string. + = D/T/DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from string according to format. = D/DT.fromordinal() # Date or datetime from days since Christ. = D/DT.fromtimestamp() # D/DT from seconds since Epoch in local time. From 458570bf01f74f459ef46a6170dce002e1405a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:14:22 +0100 Subject: [PATCH 0044/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf214fcee..57d81f398 100644 --- a/README.md +++ b/README.md @@ -495,7 +495,7 @@ import pytz ### Encode ```python = D/T/DT.fromisoformat('') # Object from ISO string. -
= DT.strptime(, '') # Datetime from string according to format. +
= DT.strptime(, '') # Datetime from string, according to format. = D/DT.fromordinal() # Date or datetime from days since Christ. = D/DT.fromtimestamp() # D/DT from seconds since Epoch in local time. = DT.utcfromtimestamp() # Naive DT from seconds since Epoch in UTC time. From f5ee7f0fc5e554a736080115ec60422270d2000d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:16:48 +0100 Subject: [PATCH 0045/1836] Datetime fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 57d81f398..6b5dc5a1b 100644 --- a/README.md +++ b/README.md @@ -496,8 +496,8 @@ import pytz ```python = D/T/DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from string, according to format. - = D/DT.fromordinal() # Date or datetime from days since Christ. - = D/DT.fromtimestamp() # D/DT from seconds since Epoch in local time. + = D/DT.fromordinal() # Object from days since Christ. + = D/DT.fromtimestamp() # Object from seconds since Epoch in local time. = DT.utcfromtimestamp() # Naive DT from seconds since Epoch in UTC time. = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` From bad760c5dd2de797150239d821b4d720a0dabfef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:18:52 +0100 Subject: [PATCH 0046/1836] Datetime fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6b5dc5a1b..993ea52cc 100644 --- a/README.md +++ b/README.md @@ -496,8 +496,8 @@ import pytz ```python = D/T/DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from string, according to format. - = D/DT.fromordinal() # Object from days since Christ. - = D/DT.fromtimestamp() # Object from seconds since Epoch in local time. + = D/DT.fromordinal() # D/DT from days since Christ. + = D/DT.fromtimestamp() # D/DT from seconds since Epoch in local time. = DT.utcfromtimestamp() # Naive DT from seconds since Epoch in UTC time. = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` From 4f9a8fde8a5f095365c5c6c3706f6e7114e567fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:21:04 +0100 Subject: [PATCH 0047/1836] Datetime fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 993ea52cc..0c11ffc91 100644 --- a/README.md +++ b/README.md @@ -508,8 +508,8 @@ import pytz ```python = .isoformat() # ISO string representation. = .strftime('') # Custom string representation. - = .toordinal() # Days since Christ, ignoring time and timezone. - =
.timestamp() # Seconds since Epoch in local time or tz if set. + = .toordinal() # Days since Christ, ignoring time and tz. + =
.timestamp() # Seconds since Epoch in local time or tz. ``` ### Format From 329502d9e74f87bdba084a2eac24a88ded560401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:23:20 +0100 Subject: [PATCH 0048/1836] Datetime fix --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0c11ffc91..c4820142a 100644 --- a/README.md +++ b/README.md @@ -518,16 +518,16 @@ import pytz ``` #### Rest of the codes: -* **`'y'` - Year, 2 digits** -* **`'b'` - Month, abbreviated name** -* **`'B'` - Month, full name** -* **`'a'` - Weekday, abbreviated name** -* **`'A'` - Weekday, full name** -* **`'I'` - Hours, 2 digits, 12 hours** -* **`'p'` - AM/PM** -* **`'f'` - Microseconds, 6 digits** -* **`'z'` - Timezone offset, ± and 4 digits** -* **`'Z'` - Timezone name** +* **`'y'` - Year, 2 digits.** +* **`'b'` - Month, abbreviated name.** +* **`'B'` - Month, full name.** +* **`'a'` - Weekday, abbreviated name.** +* **`'A'` - Weekday, full name.** +* **`'I'` - Hours, 2 digits, 12 hours.** +* **`'p'` - AM/PM.** +* **`'f'` - Microseconds, 6 digits.** +* **`'z'` - Timezone offset, ± and 4 digits.** +* **`'Z'` - Timezone name.** Arguments From cf823f25fc95ad3e6292b99b93ca8c18a6ab010e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:32:26 +0100 Subject: [PATCH 0049/1836] Datetime fix --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c4820142a..802def842 100644 --- a/README.md +++ b/README.md @@ -497,8 +497,6 @@ import pytz = D/T/DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from string, according to format. = D/DT.fromordinal() # D/DT from days since Christ. - = D/DT.fromtimestamp() # D/DT from seconds since Epoch in local time. - = DT.utcfromtimestamp() # Naive DT from seconds since Epoch in UTC time. = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** From ce969e256cfb536e900e37f71a4a394c83c39b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 03:33:39 +0100 Subject: [PATCH 0050/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 802def842..e0a4e6ec1 100644 --- a/README.md +++ b/README.md @@ -499,8 +499,8 @@ import pytz = D/DT.fromordinal() # D/DT from days since Christ. = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` -* **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** * **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[+]'`, or both separated by `'T'`.** +* **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** ### Decode ```python From 91b55481cff01720a7f824c22320347ac2b79042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 04:57:57 +0100 Subject: [PATCH 0051/1836] Datetime fix --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e0a4e6ec1..db54a5500 100644 --- a/README.md +++ b/README.md @@ -513,16 +513,13 @@ import pytz ### Format ```python >>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') +>>> dt.strftime("%dth %B '%y %A %I%p") +"14th May '15 Thursday 11PM" ``` #### Rest of the codes: -* **`'y'` - Year, 2 digits.** * **`'b'` - Month, abbreviated name.** -* **`'B'` - Month, full name.** * **`'a'` - Weekday, abbreviated name.** -* **`'A'` - Weekday, full name.** -* **`'I'` - Hours, 2 digits, 12 hours.** -* **`'p'` - AM/PM.** * **`'f'` - Microseconds, 6 digits.** * **`'z'` - Timezone offset, ± and 4 digits.** * **`'Z'` - Timezone name.** From d5e8f1274539c04128a11727f3d3a1049a159350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 05:09:46 +0100 Subject: [PATCH 0052/1836] Datetime fix --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index db54a5500..a483be9d7 100644 --- a/README.md +++ b/README.md @@ -512,17 +512,14 @@ import pytz ### Format ```python ->>> dt = datetime.strptime('2015-05-14 23:39:00', '%Y-%m-%d %H:%M:%S') ->>> dt.strftime("%dth %B '%y %A %I%p") -"14th May '15 Thursday 11PM" +>>> dt = datetime.strptime('2015-05-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z') +>>> dt.strftime("%A %dth %B '%y, %I:%m%p %Z") +"Thursday 14th May '15, 11:05PM UTC+02:00" ``` #### Rest of the codes: * **`'b'` - Month, abbreviated name.** * **`'a'` - Weekday, abbreviated name.** -* **`'f'` - Microseconds, 6 digits.** -* **`'z'` - Timezone offset, ± and 4 digits.** -* **`'Z'` - Timezone name.** Arguments From 50106d56276bc47f17cd5f6587d8b7ae704f5246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 06:24:55 +0100 Subject: [PATCH 0053/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a483be9d7..2177bfb5c 100644 --- a/README.md +++ b/README.md @@ -499,7 +499,7 @@ import pytz = D/DT.fromordinal() # D/DT from days since Christ. = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` -* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[+]'`, or both separated by `'T'`.** +* **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±]'`, or both separated by `'T'`.** * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** ### Decode From 867b347d8f736eac6f79b54e7c2c3a09880d6549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 06:26:25 +0100 Subject: [PATCH 0054/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2177bfb5c..db166e8e2 100644 --- a/README.md +++ b/README.md @@ -496,7 +496,7 @@ import pytz ```python = D/T/DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from string, according to format. - = D/DT.fromordinal() # D/DT from days since Christ. + = D/DT.fromordinal() # D/DTn from days since Christ. = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. ``` * **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±]'`, or both separated by `'T'`.** From de4fd4a46c412e239dc50cdb8befaa25eee29922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 06:27:08 +0100 Subject: [PATCH 0055/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db166e8e2..e38b023c8 100644 --- a/README.md +++ b/README.md @@ -497,7 +497,7 @@ import pytz = D/T/DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from string, according to format. = D/DT.fromordinal() # D/DTn from days since Christ. - = DT.fromtimestamp(, ) # Aware DT from seconds since Epoch in tz time. + = DT.fromtimestamp(, ) # DTa from seconds since Epoch in tz time. ``` * **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±]'`, or both separated by `'T'`.** * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** From 7ef8138ca52eb071db320dc1a52d3e625757ceec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 06:32:46 +0100 Subject: [PATCH 0056/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e38b023c8..1f763fa9f 100644 --- a/README.md +++ b/README.md @@ -487,7 +487,7 @@ import pytz ### Timezone ```python = pytz.utc # UTC timezone. - = pytz.timezone('/') # Timezone from 'Continent/City' string. + = pytz.timezone('/') # Timezone from 'Continent/City_Name' str. =
.astimezone() # Datetime, converted to passed timezone. = .replace(tzinfo=) # Unconverted object with new timezone. ``` From c5cfb61e21577bfc74d4ce3ede3bcf667fce3b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 06:41:32 +0100 Subject: [PATCH 0057/1836] Datetime fix --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1f763fa9f..9a8651895 100644 --- a/README.md +++ b/README.md @@ -512,15 +512,11 @@ import pytz ### Format ```python ->>> dt = datetime.strptime('2015-05-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z') ->>> dt.strftime("%A %dth %B '%y, %I:%m%p %Z") -"Thursday 14th May '15, 11:05PM UTC+02:00" +>>> dt = datetime.strptime('2015-06-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z') +>>> dt.strftime("%a %dth %B '%y, %I:%m%p %Z") +"Sun 14th June '15, 11:06PM UTC+02:00" ``` -#### Rest of the codes: -* **`'b'` - Month, abbreviated name.** -* **`'a'` - Weekday, abbreviated name.** - Arguments --------- From b195702e77c1c13294866ba59bd98c21e3b6c03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 06:43:28 +0100 Subject: [PATCH 0058/1836] Datetime fix --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9a8651895..1f763fa9f 100644 --- a/README.md +++ b/README.md @@ -512,11 +512,15 @@ import pytz ### Format ```python ->>> dt = datetime.strptime('2015-06-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z') ->>> dt.strftime("%a %dth %B '%y, %I:%m%p %Z") -"Sun 14th June '15, 11:06PM UTC+02:00" +>>> dt = datetime.strptime('2015-05-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z') +>>> dt.strftime("%A %dth %B '%y, %I:%m%p %Z") +"Thursday 14th May '15, 11:05PM UTC+02:00" ``` +#### Rest of the codes: +* **`'b'` - Month, abbreviated name.** +* **`'a'` - Weekday, abbreviated name.** + Arguments --------- From 64a38fc5c0170fe13eba2a2f60cb95d82ff54bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 06:44:06 +0100 Subject: [PATCH 0059/1836] Datetime fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f763fa9f..200b9abd6 100644 --- a/README.md +++ b/README.md @@ -518,8 +518,8 @@ import pytz ``` #### Rest of the codes: -* **`'b'` - Month, abbreviated name.** * **`'a'` - Weekday, abbreviated name.** +* **`'b'` - Month, abbreviated name.** Arguments From 66fffae05427fb220eb7f9c915dec433294497e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 13:53:54 +0100 Subject: [PATCH 0060/1836] Switched pytz for dateutil in datetime. --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 200b9abd6..35de87c15 100644 --- a/README.md +++ b/README.md @@ -461,9 +461,8 @@ Datetime * **If object is naive it is presumed to be in system's timezone.** ```python -# $ pip3 install pytz from datetime import date, time, datetime, timedelta -import pytz +from dateutil.tz import UTC, gettz ``` ### Constructors @@ -486,8 +485,8 @@ import pytz ### Timezone ```python - = pytz.utc # UTC timezone. - = pytz.timezone('/') # Timezone from 'Continent/City_Name' str. + = UTC # UTC timezone. + = gettz('/') # Timezone from 'Continent/City_Name' str. =
.astimezone() # Datetime, converted to passed timezone. = .replace(tzinfo=) # Unconverted object with new timezone. ``` From 6870769e5668995bdc82c1d4f326331ebcb596cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2019 22:05:39 +0100 Subject: [PATCH 0061/1836] Datetime --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35de87c15..759d4fdac 100644 --- a/README.md +++ b/README.md @@ -494,7 +494,7 @@ from dateutil.tz import UTC, gettz ### Encode ```python = D/T/DT.fromisoformat('') # Object from ISO string. -
= DT.strptime(, '') # Datetime from string, according to format. +
= DT.strptime(, '') # Datetime from str, according to format. = D/DT.fromordinal() # D/DTn from days since Christ. = DT.fromtimestamp(, ) # DTa from seconds since Epoch in tz time. ``` @@ -512,8 +512,8 @@ from dateutil.tz import UTC, gettz ### Format ```python >>> dt = datetime.strptime('2015-05-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z') ->>> dt.strftime("%A %dth %B '%y, %I:%m%p %Z") -"Thursday 14th May '15, 11:05PM UTC+02:00" +>>> dt.strftime("%A %dth %B '%y, %I:%M%p %Z") +"Thursday 14th May '15, 11:39PM UTC+02:00" ``` #### Rest of the codes: From 3b3ef77d5f0e5cc392d9ed427b953d8dfa0d2be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 17:17:10 +0100 Subject: [PATCH 0062/1836] Added logging --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 759d4fdac..5e975d0ec 100644 --- a/README.md +++ b/README.md @@ -1657,6 +1657,46 @@ def get_border(screen): ``` +Logging +------- +```python +# $ pip3 install loguru +from loguru import logger +``` + +```python +logger.add('debug_{time}.log', colorize=True) # Connects a log file. +logger.add('error_{time}.log', level='ERROR') # Adds another file for errors or higher. +logger.('A logging message') +``` +* **Levels: `'debug'`, `'info'`, `'success'`, `'warning'`, `'error'`, `'critical`'.** + +### Rotation +Parameter that sets a condition when a new log file is created. +```python +rotation=||| +``` +* **`''` - Max file size in bytes.** +* **`'`' - Max age of a file.** +* **`'
.astimezone() # Datetime, converted to passed timezone. = .replace(tzinfo=) # Unconverted object with new timezone. ``` From 5ab93d30ef72c8f48ad0e3ab51012a2970726d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 17:52:01 +0100 Subject: [PATCH 0070/1836] Removed spaces before new lines --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 976dc09e7..eb4ec7090 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,11 @@ list_of_chars = list() ``` ```python -index = .index() # Returns first index of item. +index = .index() # Returns first index of item. .insert(index, ) # Inserts item at index and moves the rest to the right. = .pop([index]) # Removes and returns item at index or from the end. .remove() # Removes first occurrence of item or raises ValueError. -.clear() # Removes all items. +.clear() # Removes all items. ``` @@ -289,9 +289,9 @@ import re ``` * **Parameter `'flags=re.IGNORECASE'` can be used with all functions.** -* **Parameter `'flags=re.DOTALL'` makes dot also accept newline.** -* **Use `r'\1'` or `'\\1'` for backreference.** -* **Use `'?'` to make operator non-greedy.** +* **Parameter `'flags=re.DOTALL'` makes dot also accept newline.** +* **Use `r'\1'` or `'\\1'` for backreference.** +* **Use `'?'` to make operator non-greedy.** ### Match Object ```python @@ -424,7 +424,7 @@ from itertools import product, combinations, combinations_with_replacement, perm ```python >>> product([0, 1], repeat=3) -[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), +[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)] ``` @@ -441,15 +441,15 @@ from itertools import product, combinations, combinations_with_replacement, perm ```python >>> combinations_with_replacement('abc', 2) -[('a', 'a'), ('a', 'b'), ('a', 'c'), - ('b', 'b'), ('b', 'c'), +[('a', 'a'), ('a', 'b'), ('a', 'c'), + ('b', 'b'), ('b', 'c'), ('c', 'c')] ``` ```python >>> permutations('abc', 2) -[('a', 'b'), ('a', 'c'), - ('b', 'a'), ('b', 'c'), +[('a', 'b'), ('a', 'c'), + ('b', 'a'), ('b', 'c'), ('c', 'a'), ('c', 'b')] ``` @@ -505,7 +505,7 @@ from dateutil.tz import UTC, tzlocal, gettz * **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±]'`, or both separated by `'T'`.** * **On Unix systems Epoch is `'1970-01-01 00:00 UTC'`, `'1970-01-01 01:00 CET'`, ...** -### Decode +### Decode ```python = .isoformat() # ISO string representation. = .strftime('') # Custom string representation. @@ -549,7 +549,7 @@ Splat Operator ```python args = (1, 2) kwargs = {'x': 3, 'y': 4, 'z': 5} -func(*args, **kwargs) +func(*args, **kwargs) ``` #### Is the same as: @@ -677,7 +677,7 @@ creature = Creature() Closure ------- **We have a closure in Python when:** -* **A nested function references a value of its enclosing function and then** +* **A nested function references a value of its enclosing function and then** * **the enclosing function returns the nested function.** ```python @@ -839,7 +839,7 @@ class MyComparable: def __eq__(self, other): if isinstance(other, type(self)): return self.a == other.a - return False + return False ``` ### Hashable @@ -857,7 +857,7 @@ class MyHashable: def __eq__(self, other): if isinstance(other, type(self)): return self.a == other.a - return False + return False def __hash__(self): return hash(self.a) ``` @@ -928,7 +928,7 @@ Enum from enum import Enum, auto class (Enum): - = + = = , = auto() @@ -1278,7 +1278,7 @@ Bytes ### Decode ```python - = .decode(encoding='utf-8') + = .decode(encoding='utf-8') = int.from_bytes(, byteorder='big|little', signed=False) = .hex() ``` @@ -1352,7 +1352,7 @@ Memory View **Used for accessing the internal data of an object that supports the buffer protocol.** ```python - = memoryview( / / ) + = memoryview( / / ) .release() ``` @@ -1494,7 +1494,7 @@ last_el = op.methodcaller('pop')() ``` -Eval +Eval ---- ### Basic ```python @@ -1555,14 +1555,14 @@ def eval_node(node): Coroutine --------- -* **Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().** -* **Coroutines provide more powerful data routing possibilities than iterators.** -* **If you built a collection of simple data processing components, you can glue them together into complex arrangements of pipes, branches, merging, etc.** +* **Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().** +* **Coroutines provide more powerful data routing possibilities than iterators.** +* **If you built a collection of simple data processing components, you can glue them together into complex arrangements of pipes, branches, merging, etc.** ### Helper Decorator -* **All coroutines must be "primed" by first calling next().** -* **Remembering to call next() is easy to forget.** -* **Solved by wrapping coroutines with a decorator:** +* **All coroutines must be "primed" by first calling next().** +* **Remembering to call next() is easy to forget.** +* **Solved by wrapping coroutines with a decorator:** ```python def coroutine(func): @@ -1691,7 +1691,7 @@ rotation=||| retention=|| ``` * **`''` - Max number of files.** -* **`''` - Max age of a file.** +* **`''` - Max age of a file.** * **`''` - Max age as a string: `'1 week, 3 days'`, `'2 months'`, ...** ### Compression From a55e023134eb2b3418a2e0d64b121c26704db7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 17:59:11 +0100 Subject: [PATCH 0071/1836] Chain --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb4ec7090..304aa1df4 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ from itertools import count, repeat, cycle, chain, islice ``` ```python - = chain(, ) # Empties collections in order. + = chain(, , ...) # Empties collections in order. = chain.from_iterable() # Empties collections inside a collection in order. ``` From a183651ea679290ea6917e57cab62274a1025887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 19:17:49 +0100 Subject: [PATCH 0072/1836] New --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 304aa1df4..c56b6e92b 100644 --- a/README.md +++ b/README.md @@ -1460,6 +1460,8 @@ class MyMetaClass(type): attrs['a'] = 'abcde' return type.__new__(cls, name, parents, attrs) ``` +* **New() is a class method that gets called before init(). It returns an instance of a class that gets passed to init() as a 'self' argument.** +* **It receives the same arguments as init(), except for the first one which is its class.** ### Metaclass Attribute **When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type.** From aee3c4dd2f1ac0bed5246fba2badeb72fc530bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 19:19:53 +0100 Subject: [PATCH 0073/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c56b6e92b..fba078e55 100644 --- a/README.md +++ b/README.md @@ -1461,7 +1461,7 @@ class MyMetaClass(type): return type.__new__(cls, name, parents, attrs) ``` * **New() is a class method that gets called before init(). It returns an instance of a class that gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one which is its class.** +* **It receives the same arguments as init(), except for the first one which, is its class.** ### Metaclass Attribute **When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type.** From 973ee455c1aa36bd7351ecfbb32e6f73aeb0b0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 19:20:22 +0100 Subject: [PATCH 0074/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fba078e55..c56b6e92b 100644 --- a/README.md +++ b/README.md @@ -1461,7 +1461,7 @@ class MyMetaClass(type): return type.__new__(cls, name, parents, attrs) ``` * **New() is a class method that gets called before init(). It returns an instance of a class that gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one which, is its class.** +* **It receives the same arguments as init(), except for the first one which is its class.** ### Metaclass Attribute **When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type.** From 98e473faa30c607e76fa31b48f5d4dd06f621f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 19:26:53 +0100 Subject: [PATCH 0075/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c56b6e92b..ca465ffd4 100644 --- a/README.md +++ b/README.md @@ -1460,7 +1460,7 @@ class MyMetaClass(type): attrs['a'] = 'abcde' return type.__new__(cls, name, parents, attrs) ``` -* **New() is a class method that gets called before init(). It returns an instance of a class that gets passed to init() as a 'self' argument.** +* **New() is a class method that gets called before init(). If it returns an instance of a class, then that instance gets passed to init() as a 'self' argument.** * **It receives the same arguments as init(), except for the first one which is its class.** ### Metaclass Attribute From d07c4a264be12faa560da108b1188b4f05972b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 19:52:14 +0100 Subject: [PATCH 0076/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca465ffd4..c8a6b438e 100644 --- a/README.md +++ b/README.md @@ -1461,7 +1461,7 @@ class MyMetaClass(type): return type.__new__(cls, name, parents, attrs) ``` * **New() is a class method that gets called before init(). If it returns an instance of a class, then that instance gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one which is its class.** +* **It receives the same arguments as init(), except for the first one which is a class.** ### Metaclass Attribute **When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type.** From 03239e5f8d50f7a8412b2d12417042ef0fcc182f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 20:11:25 +0100 Subject: [PATCH 0077/1836] New --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8a6b438e..c98fe22fe 100644 --- a/README.md +++ b/README.md @@ -1460,8 +1460,8 @@ class MyMetaClass(type): attrs['a'] = 'abcde' return type.__new__(cls, name, parents, attrs) ``` -* **New() is a class method that gets called before init(). If it returns an instance of a class, then that instance gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one which is a class.** +* **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument.** +* **It receives the same arguments as init(), except for the first one that specifies the class of returned instance.** ### Metaclass Attribute **When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type.** From 0eda219e9222a18b5cc40fd5aabaebea0f581182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 20:27:06 +0100 Subject: [PATCH 0078/1836] New --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c98fe22fe..f4d168e26 100644 --- a/README.md +++ b/README.md @@ -1460,8 +1460,8 @@ class MyMetaClass(type): attrs['a'] = 'abcde' return type.__new__(cls, name, parents, attrs) ``` -* **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one that specifies the class of returned instance.** +* **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument, unless it is called directly as in example above.** +* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance.** ### Metaclass Attribute **When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type.** From 8ea9072761f1933d93826dc98b413f0f254736e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 21:04:36 +0100 Subject: [PATCH 0079/1836] New --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f4d168e26..bf755ca51 100644 --- a/README.md +++ b/README.md @@ -1460,8 +1460,9 @@ class MyMetaClass(type): attrs['a'] = 'abcde' return type.__new__(cls, name, parents, attrs) ``` -* **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument, unless it is called directly as in example above.** +* **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument. * **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance.** +* **New() can also be called directly, usually from a new() method of a child class (`'def __new__(cls): return super().__new__(cls)'`), in which case init() is not called.** ### Metaclass Attribute **When class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type.** From df0ed251a240fe3b2bb1e63bdbb06adca2a88b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 21:05:19 +0100 Subject: [PATCH 0080/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf755ca51..0689f2dac 100644 --- a/README.md +++ b/README.md @@ -1460,7 +1460,7 @@ class MyMetaClass(type): attrs['a'] = 'abcde' return type.__new__(cls, name, parents, attrs) ``` -* **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument. +* **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument.** * **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance.** * **New() can also be called directly, usually from a new() method of a child class (`'def __new__(cls): return super().__new__(cls)'`), in which case init() is not called.** From 5be0e85f40735ea0b0805886b9d9ff34b9d62268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 21:47:28 +0100 Subject: [PATCH 0081/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0689f2dac..843071472 100644 --- a/README.md +++ b/README.md @@ -1461,7 +1461,7 @@ class MyMetaClass(type): return type.__new__(cls, name, parents, attrs) ``` * **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance.** +* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance (In this case 'MyMetaClass').** * **New() can also be called directly, usually from a new() method of a child class (`'def __new__(cls): return super().__new__(cls)'`), in which case init() is not called.** ### Metaclass Attribute From 8f39b45f8441f21db8b539c6492991bbe9e3d508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 21:47:59 +0100 Subject: [PATCH 0082/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 843071472..67fc960f9 100644 --- a/README.md +++ b/README.md @@ -1461,7 +1461,7 @@ class MyMetaClass(type): return type.__new__(cls, name, parents, attrs) ``` * **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance (In this case 'MyMetaClass').** +* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance (In our case 'MyMetaClass').** * **New() can also be called directly, usually from a new() method of a child class (`'def __new__(cls): return super().__new__(cls)'`), in which case init() is not called.** ### Metaclass Attribute From 138ada2ba1d6dbbd01f2625a31b1f53a14ed3580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 22:09:38 +0100 Subject: [PATCH 0083/1836] New --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67fc960f9..19af2df8e 100644 --- a/README.md +++ b/README.md @@ -1461,7 +1461,7 @@ class MyMetaClass(type): return type.__new__(cls, name, parents, attrs) ``` * **New() is a class method that gets called before init(). If it returns an instance of its class, then that instance gets passed to init() as a 'self' argument.** -* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance (In our case 'MyMetaClass').** +* **It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance ('MyMetaClass' in our case).** * **New() can also be called directly, usually from a new() method of a child class (`'def __new__(cls): return super().__new__(cls)'`), in which case init() is not called.** ### Metaclass Attribute From a4d38c807f96de8a8b225424190222522099e614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 23:10:56 +0100 Subject: [PATCH 0084/1836] Datetime with | instead of slashes --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 19af2df8e..e095528e7 100644 --- a/README.md +++ b/README.md @@ -473,12 +473,12 @@ from dateutil.tz import UTC, tzlocal, gettz = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) ``` -* **Use `'.weekday()'` to get the day of the week (Mon == 0).** +* **Use `'.weekday()'` to get the day of the week (Mon == 0).** * **`'fold=1'` means second pass in case of time jumping back for one hour.** ### Now ```python - = D/DT.today() # Current local date or naive datetime. + = D|DT.today() # Current local date or naive datetime. = DT.utcnow() # Naive datetime from current UTC time. = DT.now() # Aware datetime from current tz time. ``` @@ -492,14 +492,14 @@ from dateutil.tz import UTC, tzlocal, gettz ```python =
.astimezone() # Datetime, converted to passed timezone. - = .replace(tzinfo=) # Unconverted object with new timezone. + = .replace(tzinfo=) # Unconverted object with new timezone. ``` ### Encode ```python - = D/T/DT.fromisoformat('') # Object from ISO string. + = D|T|DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from str, according to format. - = D/DT.fromordinal() # D/DTn from days since Christ. + = D|DT.fromordinal() # D|DTn from days since Christ. = DT.fromtimestamp(, ) # DTa from seconds since Epoch in tz time. ``` * **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±]'`, or both separated by `'T'`.** @@ -507,9 +507,9 @@ from dateutil.tz import UTC, tzlocal, gettz ### Decode ```python - = .isoformat() # ISO string representation. - = .strftime('') # Custom string representation. - = .toordinal() # Days since Christ, ignoring time and tz. + = .isoformat() # ISO string representation. + = .strftime('') # Custom string representation. + = .toordinal() # Days since Christ, ignoring time and tz. =
.timestamp() # Seconds since Epoch in local time or tz. ``` From 2ed74a576924ab088f8a2f241de2873e7b952ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 16 Mar 2019 23:13:17 +0100 Subject: [PATCH 0085/1836] Reverted datetime --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e095528e7..19af2df8e 100644 --- a/README.md +++ b/README.md @@ -473,12 +473,12 @@ from dateutil.tz import UTC, tzlocal, gettz = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0) ``` -* **Use `'.weekday()'` to get the day of the week (Mon == 0).** +* **Use `'.weekday()'` to get the day of the week (Mon == 0).** * **`'fold=1'` means second pass in case of time jumping back for one hour.** ### Now ```python - = D|DT.today() # Current local date or naive datetime. + = D/DT.today() # Current local date or naive datetime. = DT.utcnow() # Naive datetime from current UTC time. = DT.now() # Aware datetime from current tz time. ``` @@ -492,14 +492,14 @@ from dateutil.tz import UTC, tzlocal, gettz ```python =
.astimezone() # Datetime, converted to passed timezone. - = .replace(tzinfo=) # Unconverted object with new timezone. + = .replace(tzinfo=) # Unconverted object with new timezone. ``` ### Encode ```python - = D|T|DT.fromisoformat('') # Object from ISO string. + = D/T/DT.fromisoformat('') # Object from ISO string.
= DT.strptime(, '') # Datetime from str, according to format. - = D|DT.fromordinal() # D|DTn from days since Christ. + = D/DT.fromordinal() # D/DTn from days since Christ. = DT.fromtimestamp(, ) # DTa from seconds since Epoch in tz time. ``` * **ISO strings come in following forms: `'YYYY-MM-DD'`, `'HH:MM:SS.ffffff[±]'`, or both separated by `'T'`.** @@ -507,9 +507,9 @@ from dateutil.tz import UTC, tzlocal, gettz ### Decode ```python - = .isoformat() # ISO string representation. - = .strftime('') # Custom string representation. - = .toordinal() # Days since Christ, ignoring time and tz. + = .isoformat() # ISO string representation. + = .strftime('') # Custom string representation. + = .toordinal() # Days since Christ, ignoring time and tz. =
.timestamp() # Seconds since Epoch in local time or tz. ``` From 62efe52edf534148604a65866d520a91723a5009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 17 Mar 2019 19:19:41 +0100 Subject: [PATCH 0086/1836] Link inside code test --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19af2df8e..3ea33621a 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,8 @@ Format {65:c} # 'A' {3:08b} # '00000011' -> Binary with leading zeros. {3:0<8b} # '11000000' -> Binary with trailing zeros. +[I'm an inline-style link](https://www.google.com) +'Collections' : (list) ``` #### Float presentation types: @@ -1943,7 +1945,7 @@ Image from PIL import Image ``` -#### Creates PNG image of rainbow gradient: +#### Creates PNG image of a rainbow gradient: ```python width = 100 height = 100 From 6b035d557bbc10c578b53970aa482c9f15cba2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 17 Mar 2019 19:20:15 +0100 Subject: [PATCH 0087/1836] Revert --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 3ea33621a..d6587ec1d 100644 --- a/README.md +++ b/README.md @@ -366,8 +366,6 @@ Format {65:c} # 'A' {3:08b} # '00000011' -> Binary with leading zeros. {3:0<8b} # '11000000' -> Binary with trailing zeros. -[I'm an inline-style link](https://www.google.com) -'Collections' : (list) ``` #### Float presentation types: From c6f0df84458c075705a6b501ac86baa08fed744b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 00:18:45 +0100 Subject: [PATCH 0088/1836] Decorator --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d6587ec1d..3b84e6529 100644 --- a/README.md +++ b/README.md @@ -772,6 +772,7 @@ def fib(n): * **Recursion depth is limited to 1000 by default. To increase it use `'sys.setrecursionlimit()'`.** ### Parametrized Decorator +**A decorator that accepts arguments and returns a normal decorator that accepts a function.** ```python from functools import wraps From 15c7de7b6871f374a2cdbf53c761445aa25124c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 00:23:28 +0100 Subject: [PATCH 0089/1836] Partial --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b84e6529..b78944062 100644 --- a/README.md +++ b/README.md @@ -703,7 +703,8 @@ from functools import partial ``` ```python ->>> multiply_by_3 = partial(operator.mul, 3) +>>> from operator import mul +>>> multiply_by_3 = partial(mul, 3) >>> multiply_by_3(10) 30 ``` From d6b9628557bdae51f471945c08f266c7c54afcdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 00:24:19 +0100 Subject: [PATCH 0090/1836] Partial --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b78944062..2c29cda91 100644 --- a/README.md +++ b/README.md @@ -703,8 +703,8 @@ from functools import partial ``` ```python ->>> from operator import mul ->>> multiply_by_3 = partial(mul, 3) +>>> import operator as op +>>> multiply_by_3 = partial(op.mul, 3) >>> multiply_by_3(10) 30 ``` From 0df2a3df6e573ed84a49a2ee5c2ace2c4ba40ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 00:36:13 +0100 Subject: [PATCH 0091/1836] Format --- README.md | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2c29cda91..0955428ee 100644 --- a/README.md +++ b/README.md @@ -347,12 +347,15 @@ Format {'abcde':10.3} # 'abc ' ``` -### Number Options +### Float Options ```python {1.23456:.3f} # '1.235' {1.23456:10.3f} # ' 1.235' +{1.23456:10.3e} # ' 1.235e+00' +{1.23456:10.3%} # ' 123.456%' ``` +### Int Options ```python { 123456:10,} # ' 123,456' { 123456:10_} # ' 123_456' @@ -363,22 +366,11 @@ Format ``` ```python -{65:c} # 'A' -{3:08b} # '00000011' -> Binary with leading zeros. -{3:0<8b} # '11000000' -> Binary with trailing zeros. +{90:c} # 'Z' +{90:X} # '5A' +{3:08b} # '00000011' ``` -#### Float presentation types: -* **`'f'` - Fixed point: `.f`** -* **`'%'` - Percent: `.%`** -* **`'e'` - Exponent** - -#### Integer presentation types: -* **`'c'` - character** -* **`'b'` - binary** -* **`'x'` - hex** -* **`'X'` - HEX** - Numbers ------- From 2d4274ac38ae18a26a04cc34cf9b735c5a674e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 00:39:17 +0100 Subject: [PATCH 0092/1836] Format --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 0955428ee..a4c7b6fe5 100644 --- a/README.md +++ b/README.md @@ -340,9 +340,6 @@ Format **`'!r'` calls object's repr() method, instead of format(), to get a string.** ```python {'abcde'!r:<10} # "'abcde' " -``` - -```python {'abcde':.3} # 'abc' {'abcde':10.3} # 'abc ' ``` From d415fe8c72af3275fa7c245fc785721a358c3c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 02:49:39 +0100 Subject: [PATCH 0093/1836] Inheritance --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a4c7b6fe5..84ecaeb01 100644 --- a/README.md +++ b/README.md @@ -812,7 +812,9 @@ class Person: def __init__(self, name, age): self.name = name self.age = age +``` +```python class Employee(Person): def __init__(self, name, age, staff_num): super().__init__(name, age) From 78c74b3eedeb80e93a9de346e83d6e0cd568bcd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 02:50:41 +0100 Subject: [PATCH 0094/1836] Inheritance --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 84ecaeb01..a4c7b6fe5 100644 --- a/README.md +++ b/README.md @@ -812,9 +812,7 @@ class Person: def __init__(self, name, age): self.name = name self.age = age -``` -```python class Employee(Person): def __init__(self, name, age, staff_num): super().__init__(name, age) From d9464bb1de4ba4c5c5faea82dfb4218457a9a6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 06:11:18 +0100 Subject: [PATCH 0095/1836] File --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a4c7b6fe5..15d2f3651 100644 --- a/README.md +++ b/README.md @@ -1070,11 +1070,23 @@ Open * **`'t'` - Text mode (default).** * **`'b'` - Binary mode.** -### Seek +### File ```python -.seek(0) # Move to the start of the file. -.seek(offset) # Move 'offset' chars/bytes from the start. -.seek(offset, ) # Anchor: 0 start, 1 current pos., 2 end. +.seek(0) # Move to the start of the file. +.seek(offset) # Move 'offset' chars/bytes from the start. +.seek(offset, ) # Anchor: 0 start, 1 current pos., 2 end. +``` + +```python + = .read(size=-1) # Reads 'size' chars/bytes or until EOF. + = .readline() # Returns a line. + = .readlines() # Returns a list of lines. + = next() # Returns a line using buffer. Do not mix. +``` + +```python +write() # Writes a string or bytes object. +writelines() # Writes a list of strings or bytes objects. ``` ### Read Text from File From ded0139cc4aed037b041a503eff5db1b8ecbec86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 06:20:02 +0100 Subject: [PATCH 0096/1836] Open --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15d2f3651..81cdeb632 100644 --- a/README.md +++ b/README.md @@ -1053,7 +1053,7 @@ value = args. Open ---- -**Opens file and returns a corresponding file object.** +**Opens a file and returns a corresponding file object.** ```python = open('', mode='r', encoding=None) From a9565be577e8cb8d0ce0adc734ed01f339251005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 06:23:08 +0100 Subject: [PATCH 0097/1836] File --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81cdeb632..97e603387 100644 --- a/README.md +++ b/README.md @@ -1085,8 +1085,8 @@ Open ``` ```python -write() # Writes a string or bytes object. -writelines() # Writes a list of strings or bytes objects. +.write() # Writes a string or bytes object. +.writelines() # Writes a list of strings or bytes objects. ``` ### Read Text from File From 8762d626d0ee86e571eacdd5e38c18a7c74859c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 06:24:41 +0100 Subject: [PATCH 0098/1836] File --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97e603387..62b1389fa 100644 --- a/README.md +++ b/README.md @@ -1072,8 +1072,8 @@ Open ### File ```python -.seek(0) # Move to the start of the file. -.seek(offset) # Move 'offset' chars/bytes from the start. +.seek(0) # Moves to the start of the file. +.seek(offset) # Moves 'offset' chars/bytes from the start. .seek(offset, ) # Anchor: 0 start, 1 current pos., 2 end. ``` From f1d3549c058bf14b6befed78c4d290c25bc6cc6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 19:27:27 +0100 Subject: [PATCH 0099/1836] File --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 62b1389fa..0ebe35871 100644 --- a/README.md +++ b/README.md @@ -1088,6 +1088,8 @@ Open .write() # Writes a string or bytes object. .writelines() # Writes a list of strings or bytes objects. ``` +* **No method adds or strips trailing newlines.** +* **Changes are not written until file gets closed.** ### Read Text from File ```python From 03ce3f1323f04860439c6fb0c33afc7815501465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 19:34:06 +0100 Subject: [PATCH 0100/1836] Pathlib --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ebe35871..09fa82692 100644 --- a/README.md +++ b/README.md @@ -1135,11 +1135,14 @@ cwd = Path() = .is_file() = .is_dir() = .iterdir() +``` + +```python = .glob('') ``` ```python - = str() # Returns path as string. + = str() # Returns path as a string. = .parts # Returns all components as strings. = .resolve() # Returns absolute path without symlinks. ``` From e17334034977aced3c79aceb6a06efb1e0b41af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 20:24:17 +0100 Subject: [PATCH 0101/1836] File --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09fa82692..04abcc9a9 100644 --- a/README.md +++ b/README.md @@ -1088,7 +1088,7 @@ Open .write() # Writes a string or bytes object. .writelines() # Writes a list of strings or bytes objects. ``` -* **No method adds or strips trailing newlines.** +* **Methods do not add or strip trailing newlines.** * **Changes are not written until file gets closed.** ### Read Text from File From 315ba59184c44332743a288a9cdc7479b6552052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 18 Mar 2019 20:34:56 +0100 Subject: [PATCH 0102/1836] File --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 04abcc9a9..ec3b8022b 100644 --- a/README.md +++ b/README.md @@ -1144,7 +1144,7 @@ cwd = Path() ```python = str() # Returns path as a string. = .parts # Returns all components as strings. - = .resolve() # Returns absolute path without symlinks. + = .resolve() # Returns absolute Path without symlinks. ``` ```python From ae4ad26e1c243864b64b5892e14683cf5757ddec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 00:19:28 +0100 Subject: [PATCH 0103/1836] MemoryView --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec3b8022b..bded4265d 100644 --- a/README.md +++ b/README.md @@ -1360,7 +1360,7 @@ Memory View **Used for accessing the internal data of an object that supports the buffer protocol.** ```python - = memoryview( / / ) + = memoryview() .release() ``` From d1e3e215c2ab2b34d4148e58a1c743fce4cbddba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 00:22:59 +0100 Subject: [PATCH 0104/1836] Revert --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bded4265d..ec3b8022b 100644 --- a/README.md +++ b/README.md @@ -1360,7 +1360,7 @@ Memory View **Used for accessing the internal data of an object that supports the buffer protocol.** ```python - = memoryview() + = memoryview( / / ) .release() ``` From 537a654bafab901c447e1accb647eb87fe47db3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 00:31:31 +0100 Subject: [PATCH 0105/1836] Introspection --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec3b8022b..3802ffdf8 100644 --- a/README.md +++ b/README.md @@ -1414,7 +1414,7 @@ Introspection ### Variables ```python - = dir() # Names of in-scope variables. + = dir() # Names of variables in current scope. = locals() # Dict of local variables. Also vars(). = globals() # Dict of global variables. ``` From 16faad4ce496c166b97b63bf9d6eec508a1b6559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 02:38:01 +0100 Subject: [PATCH 0106/1836] Inspect --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3802ffdf8..2828fe3b9 100644 --- a/README.md +++ b/README.md @@ -1430,9 +1430,9 @@ setattr(, '', value) ### Parameters ```python from inspect import signature -sig = signature() -no_of_params = len(sig.parameters) -param_names = list(sig.parameters.keys()) + = signature() +no_of_params = len(.parameters) +param_names = list(.parameters.keys()) ``` From 8221fe4bb6c2e06d2bab8193a5ac044cd4603026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 02:40:25 +0100 Subject: [PATCH 0107/1836] Inheritance --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 2828fe3b9..506878e4a 100644 --- a/README.md +++ b/README.md @@ -819,6 +819,11 @@ class Employee(Person): self.staff_num = staff_num ``` +```python +>>> Employee.mro() +[, , ] +``` + ### Comparable * **If eq() method is not overridden, it returns `'id(self) == id(other)'`, which is the same as `'self is other'`.** * **That means all objects compare not equal by default.** From f12f6b9bd439e91641c878685be328f8a6d51bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 04:16:02 +0100 Subject: [PATCH 0108/1836] Coroutine --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 506878e4a..5b582cd7e 100644 --- a/README.md +++ b/README.md @@ -1573,7 +1573,7 @@ Coroutine --------- * **Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().** * **Coroutines provide more powerful data routing possibilities than iterators.** -* **If you built a collection of simple data processing components, you can glue them together into complex arrangements of pipes, branches, merging, etc.** +* **If you build a collection of simple data processing components, you can glue them together into complex arrangements of pipes, branches, merging, etc.** ### Helper Decorator * **All coroutines must be "primed" by first calling next().** From bdb53e6d83bd09402dbd60e7808c133ec1ae0387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 04:17:56 +0100 Subject: [PATCH 0109/1836] Pycon test --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b582cd7e..741750c8c 100644 --- a/README.md +++ b/README.md @@ -819,7 +819,7 @@ class Employee(Person): self.staff_num = staff_num ``` -```python +```pycon >>> Employee.mro() [, , ] ``` From fe74af360d52bb3b822479c1e231679380f215b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 04:18:52 +0100 Subject: [PATCH 0110/1836] Reverte --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 741750c8c..5b582cd7e 100644 --- a/README.md +++ b/README.md @@ -819,7 +819,7 @@ class Employee(Person): self.staff_num = staff_num ``` -```pycon +```python >>> Employee.mro() [, , ] ``` From 34f74498ab9a2e4e334ea2a4139011ed4c1161dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 05:32:36 +0100 Subject: [PATCH 0111/1836] Sequence --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5b582cd7e..dceabfad8 100644 --- a/README.md +++ b/README.md @@ -869,6 +869,8 @@ class MySequence: return len(self.a) def __getitem__(self, i): return self.a[i] + def __setitem__(self, i, value): + self.a[i] = value def __iter__(self): for el in self.a: yield el From 84705b5af4da5b25d6199e6dc3613ba980fc9021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Tue, 19 Mar 2019 05:52:42 +0100 Subject: [PATCH 0112/1836] Logging --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dceabfad8..c520832ad 100644 --- a/README.md +++ b/README.md @@ -1688,7 +1688,7 @@ from loguru import logger ```python logger.add('debug_{time}.log', colorize=True) # Connects a log file. -logger.add('error_{time}.log', level='ERROR') # Adds another file for errors or higher. +logger.add('error_{time}.log', level='ERROR') # Another file for errors or higher. logger.('A logging message') ``` * **Levels: `'debug'`, `'info'`, `'success'`, `'warning'`, `'error'`, `'critical'`.** @@ -1701,7 +1701,7 @@ rotation=||| * **`''` - Max file size in bytes.** * **`''` - Max age of a file.** * **`'