파이썬 생성자 오버로딩 하는 법

myClass1(object):
1
2
3
4
5
6
7
8
    def __init__(self, *args, **kwargs):
#args -- 이름이 없는 인자를 저장하는 tuple
# #kwargs -- 이름이 있는 인자를 저장하는 dict
print "aargs:", args
print "kwargs:", kwargs
mynum = 3 if kwargs['num'] is None else kwargs['num']

o = myClass1(3, "hello", num = 1, mystring = "mystring")

  • python exeption unittest 통과 하기

    1
    2
    3
    4
    class MoneyTest(unittest.TestCase):
    def test_under_money(self):
    with self.assertRaises(LottoException):
    Money(999)
  • python input() 리턴 타입은 str