It is new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
Read more → Всего голосов 31: ↑31 и ↓0 +31
Просмотры 1.9K Добавить в закладки
2
It is new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
Previous publications:
Read more → Всего голосов 28: ↑27 и ↓1 +26
Просмотры 1.7K Добавить в закладки
5
It is new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
Previous publications .
Structures comparing
Sometimes you want to compare complex structures in tests ignoring some values. Usually, it can be done by comparing particular values with the structure:
Read more → Всего голосов 19: ↑18 и ↓1 +17
Просмотры 1.5K Добавить в закладки
1
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
Previous publications .
0_0
0_0
is a totally valid Python expression.
Read more → Всего голосов 21: ↑19 и ↓2 +17
Просмотры 2.3K Добавить в закладки
2
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
Previous publications .
Read more → Всего голосов 24: ↑23 и ↓1 +22
Просмотры 1.4K Добавить в закладки
2
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications
Read more → Всего голосов 33: ↑31 и ↓2 +29
Просмотры 1.4K Добавить в закладки
4
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications
The
\
symbol in regular string have special meaning.
\t
is tab character,
\r
is carriage return and so on.
You can use raw-strings to disable this behaviour.
r'\t'
is just backslash and
t
.
You obviously can’t use
'
inside
r'...'
. However, it still can be escaped by
\
, but
\
is preserved in the string:
Read more → Всего голосов 24: ↑20 и ↓4 +16
Просмотры 2.4K Добавить в закладки
3
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications
You can’t mutate closure variables by simply assigning them. Python treats assignment as a definition inside a function body and doesn’t make closure at all.
Read more → Всего голосов 22: ↑21 и ↓1 +20
Просмотры 1.1K Добавить в закладки
2
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications
If an instance of a class doesn’t have an attribute with the given name, it tries to access the class attribute with the same name.
>>> class A:
... x = 2
...
>>> A.x
2
>>> A().x
2
Read more → Всего голосов 29: ↑27 и ↓2 +25
Просмотры 1.4K Добавить в закладки
0
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications
Read more → Всего голосов 28: ↑26 и ↓2 +24
Просмотры 902 Добавить в закладки
2
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications
If you want to iterate over several iterables at once, you can use the
zip
function (it has nothing to do with ZIP file format):
Read more → Всего голосов 29: ↑28 и ↓1 +27
Просмотры 889 Добавить в закладки
2
Tips and tricks from my Telegram-channel @pythonetc, November 2019
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications .
PATH
is an environment variable that stores paths where executables are looked for. When you ask your shell to run
ls
, the shell looks for the
ls
executable file across all paths that are presented in PATH.
Read more → Всего голосов 31: ↑30 и ↓1 +29
Просмотры 2.1K Добавить в закладки
2
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications .
Different
asyncio
tasks obviously have different stacks. You can view at all of them at any moment using
asyncio.all_tasks()
to get all currently running tasks and
task.get_stack()
to get a stack for each task.
Read more → Всего голосов 27: ↑26 и ↓1 +25
Просмотры 1.1K Добавить в закладки
1
It is a new selection of tips and tricks about Python and programming from my Telegram-channel @pythonetc.
←
Previous publications .
The order of
except
blocks matter: if exceptions can be caught by more than one block, the higher block applies. The following code doesn’t work as intended:
Read more → Всего голосов 15: ↑15 и ↓0 +15
Просмотры 1K Добавить в закладки
0