(Have a complaint about this email? Want to make it better, fix a typo, or add more info? Fork the gist on GitHub! Or, click through to read a rendered version.)
Hello Hackers-
#!/usr/bin/env python | |
import csv | |
import json | |
# Get graffiti_locations.csv from: | |
# https://nycopendata.socrata.com/Social-Services/Graffiti-Locations/2j99-6h29? | |
filename = 'graffiti_locations.csv' |
#!/usr/bin/env python | |
# Try putting this data in a file called 'band.csv' | |
# James,Dennis,Drums,punk | |
# Rob,Spectre,Guitar,punk | |
import csv | |
import json |
>>> from schematics.models import Model | |
>>> from schematics.serialize import whitelist, blacklist | |
>>> from schematics.types import BaseType, StringType | |
>>> from schematics.exceptions import ValidationError | |
>>> import hashlib | |
>>> import random | |
>>> | |
>>> class PasswordType(BaseType): | |
... ALGORITHM = 'MD5' | |
... def __init__(self, **kw): |
>>> class ModelMeta(type): | |
... def __new__(cls, name, bases, attrs): | |
... for base in reversed(bases): | |
... print 'Base:', base | |
... return type.__new__(cls, name, bases, attrs) | |
... | |
>>> | |
>>> class A(object): | |
... def __init__(self): | |
... print 'A' |
#!/usr/bin/env python | |
import hashlib | |
from schematics.models import Model | |
from schematics.serialize import whitelist, blacklist | |
from schematics.types import MD5Type, StringType | |
from schematics.exceptions import ValidationError |
>>> class ModelOptions(object): | |
... def __init__(self, klass, namespace=None, roles={}): | |
... self.klass = klass | |
... self.namespace = namespace | |
... self.roles = roles | |
... | |
>>> mo1 = ModelOptions('foo') | |
>>> mo2 = ModelOptions('bar') | |
>>> mo1.roles['foo'] = 'foooooooo' | |
>>> mo2.roles |
>>> from schematics.models import Model | |
>>> from schematics.types import StringType, IntType, DateTimeType, BooleanType | |
>>> from schematics.types.compound import ModelType, ListType | |
>>> from schematics.exceptions import ValidationError | |
>>> from schematics.serialize import whitelist | |
>>> class Game(Model): | |
... opponent_id = IntType(required=True) | |
... | |
>>> class Player(Model): | |
... total_games = IntType(min_value=0, required=True) |
>>> from schematics.models import Model | |
>>> from schematics.types.base import StringType, DateTimeType, IntType, BooleanType | |
>>> from schematics.types.compound import ListType, ModelType | |
>>> | |
>>> class ProtoStep(Model): | |
... step_type = StringType(required=True) # enum type? | |
... deadline = DateTimeType() | |
... | |
>>> class DocumentStep(ProtoStep): | |
... doc_name = StringType() |
# Remove rogue fields | |
if len(class_fields) > 0: # if accumulation is not disabled | |
palins = data_fields - set(class_fields) | |
for rogue_field in palins: | |
del values[rogue_field] |