Skip to content

Instantly share code, notes, and snippets.

@whutch
whutch / splitfields.py
Created May 1, 2013 01:45
Generator for parsing text into fields such as command line arguments or raw CSV.
def split_fields(text, delimiters = " \t\n\r", quotes = "\"'`"):
"""
Field parsing generator; default parameters will function similar
to command line argument parsing.
Ex. >>> [f for f in split_fields("this is\t`a te's't` ")]
['this', 'is', "a te's't"]
"""
index = -1
start = -1
@whutch
whutch / gob.py
Created May 1, 2013 01:43
A one liner for Gob's Program, with delayed text writing for maximum effect.
# Python 2.7
any(__import__('time').sleep(__import__('sys').stdout.write(chr(n)) or .01) for n in __import__('itertools').cycle([80,101,110,117,115,32])) if raw_input('Gob\'s Program: Y/N?\n? ')[0].lower() == 'y' else ''
# Python 3.x
any(__import__('time').sleep(print(chr(n),end='',flush=True) or .01) for n in __import__('itertools').cycle([80,101,110,117,115,32])) if input('Gob\'s Program: Y/N?\n? ')[0].lower() == 'y' else ''