Skip to content

Instantly share code, notes, and snippets.

View iisaka51's full-sized avatar

Goichi (Iisaka) Yukawa iisaka51

View GitHub Profile
@iisaka51
iisaka51 / 00_PythonOsaka.md
Last active June 1, 2022 02:21
Python@Osaka local community for Python

Python@Osakaについて

PythonのコミュニティーとしてPython大阪の会に携わっていまして、 Scapbox でも PythonOsaka に資料を多数アップしていています。

Python@Osaka としたのはアットマーク( @ )が蛇がとぐろを巻いていようにも見えることと、 大阪でのコミュニテイーを表すのにちょうどよいと思ったしだいです。

@iisaka51
iisaka51 / singledispatchmethod.py
Last active June 1, 2022 04:06
sinpledispatchmethod for old version python
try:
# python 3.8 or later
from functools import singledispatchmethod
except ImportError:
from functools import singledispatch, update_wrapper
def singledispatchmethod(func):
dispatcher = singledispatch(func)
def wrapper(*args, **kw):
return dispatcher.dispatch(args[1].__class__)(*args, **kw)
@iisaka51
iisaka51 / using_dataset_with_read_contents.py
Created October 25, 2022 04:18
example of read_contests
In [1]: from datajuggler import serializer as io
In [2]: io.read_contents('sqlite:///users.sqlite#users')
Out[2]:
[{'id': 1, 'name': 'David Coverdale', 'age': 71, 'belongs': 'Whitesnake'},
{'id': 2, 'name': 'Neal Schon ', 'age': 68, 'belongs': 'Journey'},
{'id': 3, 'name': 'Tom Scholz', 'age': 75, 'belongs': 'Boston'},
{'id': 4, 'name': 'David Gilmour', 'age': 75, 'belongs': 'Pink Floyd'},
{'id': 5, 'name': 'Ann Wilson', 'age': 71, 'belongs': 'Heart'},
{'id': 6, 'name': 'Nacy Wilson', 'age': 67, 'belongs': 'Heart'}]
@iisaka51
iisaka51 / users_class.py
Created October 25, 2022 04:24
example of class define
In [8]: # %load users_class.py
...: class User:
...:
...: def __init__(self, *nargs, **kwargs):
...: self.data = dict(*nargs, **kwargs)
...: self.id: int = self.data['id']
...: self.name: str = self.data['name']
...: self.age: int = self.data['age']
...: self.belongs: str = self.data['belongs']
...:
@iisaka51
iisaka51 / users_class_no_repr.py
Created October 25, 2022 04:26
users_class not define __repr__
In [4]: class User:
...:
...: def __init__(self, *nargs, **kwargs):
...: self.data = dict(*nargs, **kwargs)
...: self.id: int = self.data['id']
...: self.name: str = self.data['name']
...: self.age: int = self.data['age']
...: self.belongs: str = self.data['belongs']
...:
@iisaka51
iisaka51 / namedtuple_cannot_overwrite_init.py
Created October 25, 2022 04:31
namedtuple cannot overwrite __init__()
In [18]: from typing import NamedTuple
...:
...: try:
...: class User(NamedTuple):
...: id: int
...: name: str
...: age: int
...: belongs: str
...:
...: def __init__(self, profile):
@iisaka51
iisaka51 / users_class_with_namedtuple.py
Created October 25, 2022 04:34
example of inheritance of NamedTuple
In [20]: from typing import NamedTuple
...:
...: class UserBase(NamedTuple):
...: id: int
...: name: str
...: age: int
...: belongs: str
...:
...: class User(UserBase):
...: def __new__(cls, profile):
@iisaka51
iisaka51 / users_class_using_dataclass.py
Created October 25, 2022 04:38
disapointment of dataclass
In [1]: from datajuggler import serializer as io
In [2]: from dataclasses import dataclass, field
...:
...: @dataclass
...: class User:
...: id: int = field(init=False)
...: name: str = field(init=False)
...: age: int = field(init=False)
...: belongs: str = field(init=False)
@iisaka51
iisaka51 / users_class_with_adict.py
Created October 25, 2022 04:40
users class with aDict
In [1]: from datajuggler import serializer as io
In [2]: from datajuggler import aDict
In [3]: class User(aDict):
...: pass
...:
In [4]: users = io.read_contents('sqlite:///users.sqlite#users',row_type=User)
@iisaka51
iisaka51 / adict_immutable.py
Created October 25, 2022 04:42
adict immuatble
In [8]: users[0].freeze()
In [9]: try:
...: users[0].age=20
...: except AttributeError as e:
...: print(e)
...:
User frozen object cannot be modified.
In [10]: