A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| from django.http import Http404 | |
| from django.shortcuts import render_to_response | |
| from django.template import RequestContext, TemplateDoesNotExist | |
| def content(request, template_name): | |
| try: | |
| return render_to_response('content/' + template_name + '.html', {}, RequestContext(request)) | |
| except TemplateDoesNotExist: | |
| raise Http404 |
| from os import path | |
| from django.conf import settings | |
| DOCUMENT_ROOT = path.dirname(path.realpath(__file__)) | |
| urlpatterns += patterns('', | |
| url(r'^robots\.txt$', 'django.views.static.serve', { | |
| 'path': settings.STATIC_URL + 'robots.txt', | |
| 'document_root': DOCUMENT_ROOT, |
| // http://jsfiddle.net/D8VQs/ | |
| function print(str, obj) { | |
| console.log(str, obj); | |
| // Use jQuery if it's available | |
| if (typeof($) != 'undefined') { | |
| var $output = $('#output'); | |
| if ($output) { |
Web basics
| abaci.io | |
| aback.io | |
| abaft.io | |
| abase.io | |
| abash.io | |
| abate.io | |
| abbe.io | |
| abbess.io | |
| abbey.io | |
| abbot.io |
| import requests | |
| gist_url = 'https://gist.github.com/isaacbw/6831088/raw/33b0072c6160f0fe304e998fa04715117456414d/available.txt' | |
| gist_response = requests.get(gist_url) | |
| if gist_response.ok: | |
| with open('available.txt', 'w') as file: | |
| lines = gist_response.content.split('\n') | |
| available_count = 0 |
[dsn]
Driver = FreeTDS
Server = SERVER
Database = DATABASE
Port = 1604
| env ARCHFLAGS='-arch i386 -arch x86_64' pip install {PACKAGE_NAME} | |
| e.g. env ARCHFLAGS='-arch i386 -arch x86_64' pip install psycopg2 |
| import urllib2 | |
| from multiprocessing.dummy import Pool as ThreadPool | |
| urls = [ | |
| 'http://www.python.org', | |
| 'http://www.python.org/about/', | |
| ] | |
| pool = ThreadPool() |