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
| # Python3 | |
| >>> try: | |
| ... raise ValueError() | |
| ... except ValueError: | |
| ... raise IndexError() | |
| ... | |
| Traceback (most recent call last): | |
| File "<stdin>", line 2, in <module> | |
| 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
| ➜ ~ cat foo.py | |
| x = tuple(set(["a", "b"])) | |
| y = tuple(set(["b", "a"])) | |
| print(x == y) | |
| ➜ ~ python3.5 foo.py | |
| False | |
| ➜ ~ python3.5 foo.py | |
| False | |
| ➜ ~ python3.5 foo.py | |
| True |
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
| """ | |
| Example state machine with conditions. | |
| """ | |
| from functools import partialmethod | |
| " Possible states." | |
| WORK = 'Work' | |
| TRAVEL = 'Travel' |
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
| """ | |
| Simple module for microservices. | |
| """ | |
| import configparser | |
| import json | |
| import os | |
| from routes import Mapper | |
| import waitress |
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 functools import partial | |
| import sched | |
| import time | |
| class Scheduler: | |
| """ | |
| A wrapper around a scheduler class providing | |
| a simple API for recurring events. | |
| """ |
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 make_url(base, *fragments): | |
| """ | |
| >>> make_url('http://example.com', '1', '2', '3.html') | |
| 'http://example.com/1/2/3.html' | |
| """ | |
| path = str(pathlib.Path(*fragments)) | |
| return urllib.parse.urljoin(base, path) |
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
| # Idea shamelessly stolen from pyramid. | |
| # utils.py | |
| from collections import Mapping | |
| from functools import wraps | |
| from flask import has_request_context, render_template | |
| def render_dict_template(template): |
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
| """ | |
| Super simple construction free roam RPG. | |
| """ | |
| from itertools import product | |
| import os | |
| import sys | |
| from getch import getch | |
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 random import SystemRandom | |
| random = SystemRandom() | |
| INPUT_FILE = '6944719-tree-sunset-reflection.bmp' | |
| OUTPUT_FILE = 'glitch.bmp' | |
| with open(INPUT_FILE, 'rb') as rh: | |
| with open(OUTPUT_FILE, 'wb') as wh: |
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
| >>> a = 1, | |
| >>> assert (1,) == a | |
| >>> a | |
| (1,) | |
| >>> l = [] | |
| >>> l.append(a) | |
| >>> l | |
| [(1,)] | |
| >>> l.append(1,) | |
| >>> l |