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, b, c = 1, 2, 3 | |
>>> a, b, c | |
(1, 2, 3) | |
>>> a, b, c = [1, 2, 3] | |
>>> a, b, c | |
(1, 2, 3) | |
>>> a, b, c = (2 * i + 1 for i in range(3)) | |
>>> a, b, c | |
(1, 3, 5) | |
>>> a, (b, c), d = [1, (2, 3), 4] |
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 contextlib import contextmanager | |
@contextmanager | |
def tag(name): | |
print("<%s>" % name) | |
yield | |
print("</%s>" % name) | |
>>> with tag("h1"): | |
... print("foo") |
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: http://blog.elsdoerfer.name/2012/07/26/make-pyyaml-output-an-ordereddict/ | |
Make PyYAML output an OrderedDict. | |
It will do so fine if you use yaml.dump(), but that generates ugly, | |
non-standard YAML code. | |
To use yaml.safe_dump(), you need the following. | |
""" | |
def represent_odict(dump, tag, mapping, flow_style=None): | |
"""Like BaseRepresenter.represent_mapping, but does not issue the sort(). |
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
# http://stackoverflow.com/questions/3964681/find-all-files-in-directory-with-extension-txt-in-python | |
# Using glob | |
import glob, os | |
os.chdir("/mydir") | |
for file in glob.glob("*.txt"): | |
print(file) | |
# Using listdir | |
import os | |
for file in os.listdir("/mydir"): |
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
# Compress with gzip | |
tar -zcvf myTar.tar.gz *.files | |
# Uncompress with gzip, http://www.cyberciti.biz/faq/tar-extract-linux/ | |
tar -xzvf myTar.tar.gz | |
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
# If bucket is private | |
AWS_ACCESS_KEY = 'your access key' | |
AWS_SECRET_KEY = 'your secret key' | |
AWS_REGION = 'your region' | |
session = boto3.session.Session( | |
aws_access_key_id=AWS_ACCESS_KEY, | |
aws_secret_access_key=AWS_SECRET_KEY, | |
region_name=AWS_REGION | |
) |
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 shlex | |
import subprocess | |
from subprocess import PIPE, STDOUT | |
from django.core.management.base import BaseCommand | |
class Command(BaseCommand): | |
help = 'Kill local processes running runserver command' |
NewerOlder