Skip to content

Instantly share code, notes, and snippets.

View andrealmar's full-sized avatar
🏠
Working from home

Andre Almar andrealmar

🏠
Working from home
View GitHub Profile
@andrealmar
andrealmar / beautiful_idiomatic_python.md
Created May 23, 2017 04:00 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
on settings.py change the DATABASES config to something like this:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "[YOUR_DATABASE_NAME]",
"USER": "[YOUR_USER_NAME]",
"PASSWORD": "",
"HOST": "localhost",
"PORT": "",
# JSON Resume
[JSON Resume] is an easy way to produce an adaptible and professional-looking resume. We recommend that you use it. It'll save you a lot of headaches about formatting, file types, and the like. Plus, it'll make you look like you know how to Internet.
This is what the underlying format looks like:
```
{
"basics": {
"name": "John Doe",
"label": "Programmer",
virtualenv -p /Users/andrealmar/.pyenv/versions/3.6.0/bin/python .venv
import logging
import os
from time import time
import asyncio
import aiohttp
from download import setup_download_dir, get_links
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
import logging
import os
from redis import Redis
from rq import Queue
from download import setup_download_dir, get_links, download_link
import logging
import os
from functools import partial
from multiprocessing.pool import Pool
from time import time
from download import setup_download_dir, get_links, download_link
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
import logging
import os
from queue import Queue
from threading import Thread
from time import time
from download import setup_download_dir, get_links, download_link
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
import json
import logging
import os
from pathlib import Path
from urllib.request import urlopen, Request
logger = logging.getLogger(__name__)
types = {'image/jpeg', 'image/png'}
import logging
import os
from time import time
from download import setup_download_dir, get_links, download_link
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)