[ create a new paste ] login | about

Link: http://codepad.org/yTPLcpys    [ raw code | output | fork ]

akx - Python, pasted on Jan 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
class Base:
	@classmethod
	def get(cls, id):
		print "Would instantiate a new %r with ID %d."%(cls, id)

class Puppy(Base):
	pass
	
class Kitten(Base):
	pass

p = Puppy.get(1)
k = Kitten.get(1)


Output:
1
2
Would instantiate a new <class __main__.Puppy at 0x403533ec> with ID 1.
Would instantiate a new <class __main__.Kitten at 0x4035341c> with ID 1.


Create a new paste based on this one


Comments: