qianqianling 发表于 2015-11-30 10:19:33

python笔记之编程风格大比拼

def new(cls, *args, **kwargs):  return cls(*args, **kwargs)
  
  class Number(object):
  pass
  
  class IntegralNumber(int, Number):
  def toInt(self):
  return new (int, self)
  
  class InternalBase(object):
  def __init__(self, base):
  self.base = base.toInt()
  
  def getBase(self):
  return new (IntegralNumber, self.base)
  
  class MathematicsSystem(object):
  def __init__(self, ibase):
  Abstract
  
  @classmethod
  def getInstance(cls, ibase):
  try:
  cls.__instance
  except AttributeError:
  cls.__instance = new (cls, ibase)
  return cls.__instance
  
  class StandardMathematicsSystem(MathematicsSystem):
  def __init__(self, ibase):
  if ibase.getBase() != new (IntegralNumber, 2):
  raise NotImplementedError
  self.base = ibase.getBase()
  
  def calculateFactorial(self, target):
  result = new (IntegralNumber, 1)
  i = new (IntegralNumber, 2)

  while i
页: [1]
查看完整版本: python笔记之编程风格大比拼