This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
class Bird(object): | |
def __init__(self, name): | |
self.name = name | |
def fly(self): | |
print self.name + " can fly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import atexit | |
import signal | |
import time | |
def shutdown(): | |
"""function when exit, exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
class decorator(object): | |
def __init__(self, f): | |
print("inside decorator.__init__()") | |
f() # Prove that function definition has completed | |
def __call__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyData: | |
def __init__(self, max): | |
self.max = max | |
self.n = 0 | |
def __iter__(self): | |
return self | |
def __str__(self): | |
return "test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import argparse | |
def parse_args(): | |
parser = argparse.ArgumentParser(description="example") | |
parser.add_argument('-s', dest='singlevalue', action='store', help='store a value') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import os | |
import sys | |
import logging | |
LOG_FILE = 'error.log' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license. | |
# | |
import ctypes | |
import logging | |
import os | |
class ColorizingStreamHandler(logging.StreamHandler): | |
# color names to indices | |
color_map = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
import time | |
from functools import wraps | |
class TimeoutException(Exception): | |
pass | |
def timethis(func): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test(object): | |
def __init__(self): | |
print "hello" | |
def __enter__(self): | |
print "enter" | |
def __call__(self, msg): | |
print "call " + str(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def string_process(string, encrypt): | |
int_list = [] | |
for s in string: | |
int_list.append(ord(s)) | |
result = '' | |
for i in int_list: | |
if i >= ord('A') and i <= ord('z'): | |
if encrypt: | |
result += chr(i - 3) |
OlderNewer