#!/usr/bin/env python
# coding=utf-8


def func1(lens):
    for i in xrange(lens):
        print(i)


def p1():
    print(" ... 1")

def p2():
    print(" ... 2")

def pxx():
    print(" ... pxx")



# test func

def test_func():
    print('\n------- test func ------')
    print("... style 1 ...")
    func1(3)

    print("... style 2 ...")
    f = func1
    f(4)

    # not use: {1:'p1', ...}
    func_dict = {1: p1, 2:p2, 3:pxx}

    for x in func_dict.iterkeys():
        print('--dict %s' % x)
        func_dict[x]()




# object oriented programming
# advanced programming

class animal:
    def __init__(self, name):
        self.name = name
        print(self.name)


    def say_name(self):
        print(self.name)

    @staticmethod
    def say_no_name():
        print('static method xxx')

    @staticmethod
    def print_help():
        print('this is a class for gen animal')


def test_animal():
    print('\n--- test animal ---')
    a1 = animal(u'cat')
    a1.say_name()
    a1.say_no_name()
    animal.print_help()
    animal.say_no_name()



class A():
    def __init__(self, name):
        self.name = name
        print("constructor A was called!")
        print("name is %s" % self.name)
        
class B(A):
    def __init__(self, name, age):
        A.__init__(self, name)
        self.age = age
        print("constructor B was called!")
        print("age is %d" % self.age)
        
class C(B):
    def __init__(self, name, age):
        B.__init__(self, name, age)
        print("constructor C was called!")

    
def test_contructor():
    print('\n------- test constructor ------')
    c = C("ccc", 23)
    print("c's name is %s" % c.name)
    print("c's age is %s" % c.age)
    # if use var '__name', then can't use c.__name outside the class
    # also for method name, eg:
    # def __xxx()



test_func()
test_animal()
test_contructor()


