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 iterclass(object): | |
def __iter__(self): | |
for i in range(10): | |
yield i | |
print iter(iterclass) |
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
# -*- coding: utf-8 -*- | |
print u'ABCDE\u3042\u3044\u3046\u3048\u304a' |
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
from System import GC | |
class C(object): | |
_instance = None | |
def __new__(cls): | |
if C._instance is None: | |
C._instance = object.__new__(cls) | |
return C._instance |
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 time | |
import datetime | |
import sys | |
_ordinal_1899_12_31=datetime.date(1899,12,31).toordinal()-1 | |
def COMDateFromTuple(YMDHMSmsTuple): | |
d = datetime.date(YMDHMSmsTuple[0],YMDHMSmsTuple[1],YMDHMSmsTuple[2]) | |
integerPart = d.toordinal() - _ordinal_1899_12_31 | |
ms = ((YMDHMSmsTuple[3]*60 \ | |
+YMDHMSmsTuple[4])*60 \ |
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 time | |
import sys | |
def Date(year,month,day): | |
return Timestamp(year,month,day,0,0,0) | |
def Timestamp(year,month,day,hour,minute,second): | |
return time.localtime(time.mktime((year,month,day,hour,minute,second,0,0,-1))) | |
def DateObjectToIsoFormatString(obj): |
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
from timeit import Timer | |
class Timing: | |
def __init__(self, name, num, init, statement): | |
self.__timer = Timer(statement, init) | |
self.__num = num | |
self.name = name | |
self.statement = statement | |
self.__result = None | |
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 types | |
class cached_property(object): | |
no_value = object() | |
def __init__(self, fget): | |
self.fget = fget | |
self.name = '_' + fget.__name__ | |
def __get__(self, obj, cls): |
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) 2005-2007 Seo Sanghyeon | |
# A chapter from Dan Wahlin's "XML for ASP.NET Developers" is useful | |
# for understanding this code. Posted to informit.com, 2002-02-22. | |
# http://www.informit.com/articles/article.asp?p=25485 | |
# 2005-11-16 sanxiyn Created | |
# 2006-08-18 sanxiyn Merged changes from Mark Rees | |
# * Adapted to the new way to load .NET libraries | |
# * Handle empty elements |
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
# test2_close.py | |
from __future__ import with_statement | |
import types | |
import itertools | |
# Patching itertools.chain: | |
class chain(object): |
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 Loader(object): | |
def load_module(self, fullname): | |
return None | |
class MetaImporter(object): | |
def find_module(self, fullname, path=None): | |
return Loader() | |
import sys | |
sys.meta_path.append(MetaImporter()) |