Size: a a a

2020 June 24

DS

David Shiko in SPb Python
∀lǝxǝʎ
и при этом работает? Ну, ты Кузьмич оригинал!
Lol, У меня сеть отвалилась)
источник

DA

Dmitry Alimov in SPb Python
Alexander
Бары же закрыты
Да, но там есть небольшое пространство на улице.
источник
2020 June 25

D

Dmitry in SPb Python
источник

DA

Dmitry Alimov in SPb Python
)))
источник

DS

David Shiko in SPb Python
Кто то кроме меня пришел на митап?
источник

DA

Dmitry Alimov in SPb Python
David Shiko
Кто то кроме меня пришел на митап?
Да
источник
2020 June 26

DI

Danil Ivanov in SPb Python
David Shiko
Кто то кроме меня пришел на митап?
источник

DI

Danil Ivanov in SPb Python
David Shiko
Кто то кроме меня пришел на митап?
источник

M

Mike in SPb Python
,kjjjjjj
источник

M

Mike in SPb Python
четверг же
источник

M

Mike in SPb Python
источник

DI

Danil Ivanov in SPb Python
On this Tuesday, a team of 5 authors (including Guido van Rossum) published PEP-622. This is a huge draft in terms of size, complexity, and impact. It is a proposal to extend Python syntax to support structural pattern matching. Think about it as if statement on steroids.

A small example using match as switch statement:

def http_error(status: int) -> str:
 match status:
   case 400:
       return 'Bad request'
   case 401:
       return 'Unauthorized'
   case _:
       return 'Something else'


Impractical but reach example:

def inspect(obj) -> None:
 match obj:
   case 0 | 1 | 2:   # matching 2 or more exact values
     print('small number')
   case x if x > 2:  # guards
     print('big positive number')
   case [] | [_]:    # matching sequence
     print('zero or one element sequence')
   case [x, _, *_]:  # unpacking to match rest
     print('2 or more elements sequence')
     print(f'the first element is {x}')
   case {'route': route}:  # matching dicts
     print(f'dict with ONLY `route` key which is {route}')
   case {'route': _, **_}:  # matching rest for dicts
     print(f'dict with `route` key')
   case str() | bytes():  # matching types
     print('something string-like')
   case [x := [_, *_]]:  # walrus and sub-patterns
     print('non-empty list inside a list')
   case _:  # default case
     print('something else')


For objects, the check is implemented via __match__ magic method. For object it does isinstance check. This is why case str() works:

class object:
 @classmethod
 def __match__(cls, obj):
   if isinstance(obj, cls):
     return obj


Also, it is possible to match objects' attributes:

class Point:
 def __init__(self, x, y):
   self.x = x
   self.y = y

match obj:
 case Point(x=0, y=0):
   print('both x and y are zero')
 case Point():
   print('it is a point')
 case _:
   print('something else')


Also, if a class has __match_args__, the given arguments can be positional in the pattern:

class Point:
 __match_args__ = ['x', 'y']

 def __init__(self, x, y):
   self.x = x
   self.y = y

match obj:
 case Point(0, 0):  # here args are positional now
   print('both x and y are zero')


You already can try it using patma. It is a fork of CPython with the reference implementation of the draft. It is expected to land into Python in 3.10 release.
источник

DS

David Shiko in SPb Python
Всем привет. Кто то знает как парсить сайты с beautifulsoup предварительно залогинившись через google аккаунт?
источник

A

Albert in SPb Python
источник

DS

Denis S in SPb Python
David Shiko
Всем привет. Кто то знает как парсить сайты с beautifulsoup предварительно залогинившись через google аккаунт?
google знает
источник
2020 June 27

DS

Denis S in SPb Python
David Shiko
Всем привет. Кто то знает как парсить сайты с beautifulsoup предварительно залогинившись через google аккаунт?
Через beautifulsoup не получится. Только selenium позволит сделать авторизацию. В нем дальше и парсить сайт.
источник

KT

Kirill Tereshchenko in SPb Python
Всем привет 👋🏻
Подскажите, где публикуется инфа или трансляции с прошедших встреч?
источник
2020 June 28

МС

Мак Сим in SPb Python
Hello! Подскажите проверку на существование email написать? Нужно сделать проверочных запрос и если ответ сервера 250 то True.
источник

A

Alexander in SPb Python
Мак Сим
Hello! Подскажите проверку на существование email написать? Нужно сделать проверочных запрос и если ответ сервера 250 то True.
стопроцентно - никак. Всё зависит от того, насколько приближенный результат вам нужен
источник

A

Alexander in SPb Python
Я недавно заморачивался с валидацией email и перечитал некоторое количество информации на этот счёт. Чтобы убедиться, что адрес валиден, нужно послать тестовый запрос на MX сервер, но далеко не факт что он вам ответит как надо
источник