This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
import requests | |
except Exception: | |
from pip._internal.main import main as pip_main | |
pip_main(['install', 'requests']) | |
import requests | |
print(f"installed requests version {requests.__version__}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass, field | |
from typing import ClassVar, List | |
@dataclass | |
class Veget: | |
index: int = field(init=False) | |
name: str | |
price: float | |
quantity: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code that I would write in an interactive session to perform a re.search or re.sub | |
# setup code | |
>>> import re | |
>>> text = open('lorem_ipsum.txt').read() # filled with https://loremipsum.io/generator/?n=99&t=p | |
>>> regex = re.compile('foo') | |
# test code for re.search | |
>>> regex.search(text) # returns None, there is no foo in lorem ipsum it seems |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[run] | |
branch = True | |
source = my_django_lib | |
omit = | |
src/my_django_lib/settings.py | |
*/__init__.py | |
[paths] | |
source = src |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__version__ = '1.2.3' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from subprocess import run, PIPE, STDOUT | |
# set pipes | |
IN_IDLE = 'idlelib' in sys.modules | |
if IN_IDLE: | |
STD_OUT = PIPE | |
STD_ERR = STDOUT | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
class Proxy: | |
def __init__(self, instance): | |
self.instance = instance | |
self.last_call = None | |
self.call_map = defaultdict(int) | |
def __getattr__(self, name): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def a(self): | |
return self | |
# write, and optionally modify class A in a way where the following will work | |
inst = A() | |
print(inst.sub.a() is inst) # True | |
# ------------------------------------- instance methods through class binding | |
# if there were no subspace, this would just work: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# no callstack, we directly crash through to the intepreter | |
>>> raise ValueError() | |
Traceback (most recent call last): | |
File "<input>", line 1, in <module> | |
ValueError | |
# we raise in a function, we crash to line two, which called the function | |
>>> def a(): | |
... raise ValueError() | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import InitVar, field, dataclass | |
import typing | |
import inspect | |
import re | |
CV = typing.ClassVar # this kills the regex ._. | |
@dataclass | |
class Foo: |