Skip to content

Instantly share code, notes, and snippets.

@jdotjdot
jdotjdot / csv_DictWriter.py
Created September 29, 2014 00:01
Python's csv module's DictWriter
class DictWriter:
def __init__(self, f, fieldnames, restval="", extrasaction="raise",
dialect="excel", *args, **kwds):
self.fieldnames = fieldnames # list of keys for the dict
self.restval = restval # for writing short dicts
if extrasaction.lower() not in ("raise", "ignore"):
raise ValueError, \
("extrasaction (%s) must be 'raise' or 'ignore'" %
extrasaction)
self.extrasaction = extrasaction

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post

@jdotjdot
jdotjdot / destroybooleans.py
Last active August 29, 2015 14:02
Example of an awful thing you shouldn't do to anyone in Python
# For some reason, in Python 2.x True and False are both constants--meaning that
# they can have new values assigned to them.
# This malicious script exploits that. Upon import, will reverse
# True and False for all modules in the current Python environment.
# This obviously can have serious consequences.
import sys
# If we reverse them by still using the `bool` type, checking if type(False)==bool
# won't help us catch this