Skip to content

Instantly share code, notes, and snippets.

View pybites's full-sized avatar

Pybites pybites

View GitHub Profile
from importlib import import_module
from keyword import kwlist
import builtins
from typing import Dict, List
scores = {
"builtin": 1,
"keyword": 2,
"module": 3,
}
import os
filename = 'homework.txt'
if not os.path.exists(filename):
with open(filename, 'w'): pass
answer1 = """1).
X | 3 | X
____|____|____
@pybites
pybites / amzlink.py
Last active December 17, 2020 15:21
#!/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)
>>> 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()
# 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)
# cars.py
from datetime import date
class Car:
def __init__(self, model, year):
self.model = model
self.year = year
self._mileage = []
@pybites
pybites / tictactoe.py
Last active August 19, 2020 09:59
A simple tictactoe game including AI
'''Simple tictactoe game, board positions are like keyboard
7 8 9
4 5 6
1 2 3
'''
from builtins import input
from collections import Counter
from functools import wraps
import itertools
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')
@pybites
pybites / slack-community.py
Created April 22, 2018 04:53
script to get timezone distribution of our slack community
from collections import Counter
import os
import sys
from slackclient import SlackClient
token = os.environ.get('SLACK_TOKEN') or sys.exit('need slack api token')
client = SlackClient(token)
users = client.api_call("users.list")
timezones = Counter()