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 BaseBase(object): | |
def method(self): | |
print "BaseBase" | |
a = BaseBase() | |
a.method() | |
class Base1(BaseBase): | |
pass |
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 A(object): | |
def __init__(self): | |
print "A" | |
super(A, self).__init__() | |
class B(object): | |
def __init__(self): | |
print "B" | |
super(B, self).__init__() | |
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 -*- | |
""" Command line interface to difflib.py providing diffs in four formats: | |
* ndiff: lists every line and highlights interline changes. | |
* context: highlights clusters of changes in a before/after format. | |
* unified: highlights clusters of changes in an inline format. | |
* html: generates side by side comparison with change highlights. | |
""" |
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 sys | |
from opus7.exception import * | |
#{ | |
class LinkedList(object): | |
""" | |
Linked list class. | |
""" | |
#}@head |
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
# file test.py | |
import cmd | |
class HelloWorld(cmd.Cmd): | |
def do_greet(self,person=''): | |
print "hello,",person | |
def help_greet(self): | |
print '\n'.join(['greet [person]', | |
'greet the named person', | |
]) | |
def complete_greet(self,text,line,begidx,endix): |
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
#Example | |
import functools | |
@functools.total_ordering | |
class Job(object): | |
def __init__(self,priority,descr): | |
self.priority = priority | |
self.descr = descr | |
def __eq__(self,other): |
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
#descriptor example | |
class RevealAccess(object): | |
def __init__(self,initval=None,name='var'): | |
self.val = initval | |
self.name = name | |
def __get__(self,obj,objtype): | |
print "Retrieving",self.name | |
return self.val |
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
#code sample | |
# from wiki.python.org/moin/SimplePrograms | |
# "1 line: Output" | |
print "hello,world" | |
# 2 lines: input,assignment | |
name= raw_input('What is your name?\n') | |
print 'Hi %s.' % name |
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 QuickFindUF(object): | |
def __init__(self,N): | |
self.__id = [] | |
for i in range(N): | |
self.__id.append(i) | |
def connected(self,p,q): | |
return self.__id[p] == self.__id[q] |
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 WeightedQuickUnionUF(object): | |
def __init__(self,N): | |
self.__id = [] | |
self.sz = [] | |
for i in range(N): | |
self.__id.append(i) | |
self.sz.append(1) | |
def root(self,i): | |
while(i!=self.__id[i]): |