This file contains 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 | |
filename = 'homework.txt' | |
if not os.path.exists(filename): | |
with open(filename, 'w'): pass | |
answer1 = """1). | |
X | 3 | X | |
____|____|____ |
This file contains 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 datetime import datetime | |
>>> def today(dt=datetime.now()): | |
... print(dt) | |
... | |
>>> today() | |
2020-12-12 22:18:26.432268 | |
# oops | |
>>> today() | |
2020-12-12 22:18:26.432268 | |
>>> today() |
This file contains 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
#!/usr/bin/env python3.9 | |
import argparse | |
import importlib | |
import inspect | |
import pydoc | |
def get_callable(arg): | |
module_str, name = arg.rsplit(".", 1) | |
module = importlib.import_module(module_str) |
This file contains 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 Fluent Python 2nd ed | |
class Averager(): | |
def __init__(self): | |
self.series = [] | |
def __call__(self, new_value): | |
self.series.append(new_value) | |
total = sum(self.series) |
This file contains 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
# cars.py | |
from datetime import date | |
class Car: | |
def __init__(self, model, year): | |
self.model = model | |
self.year = year | |
self._mileage = [] |
This file contains 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 concurrent.futures | |
import os | |
import re | |
from timeit import timeit | |
import requests | |
from tqdm import tqdm | |
URLS = 'urls' |
This file contains 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 concurrent.futures | |
import os | |
import re | |
from timeit import timeit | |
import requests | |
URLS = 'urls' | |
This file contains 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 re | |
import pyperclip | |
def gen_affiliation_link(url): | |
if not re.search(r"amazon.*/dp/", url): | |
raise ValueError(f"{url} is not a valid Amazon product link") | |
asin = re.sub(r".*/dp/([^/]+).*", r"\1", url) |
This file contains 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 | |
# make venv and pip install selenium | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
# set your codechalleng.es username and password in venv/bin/activate, then source it | |
user = os.getenv('PB_USER') | |
password = os.getenv('PB_PW') |
This file contains 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
{"achievementPoints": 14565, | |
"battlegroup": "Cyclone", | |
"calcClass": "V", | |
"class": 9, | |
"faction": 0, | |
"gender": 0, | |
"lastModified": 1519011260000, | |
"level": 110, | |
"mounts": {"collected": [{"creatureId": 32158, | |
"icon": "ability_mount_drake_blue", |