Discuss / Python / ...

神月宗

#1 Created at ... [Delete] [Delete and Lock User]

#coding=utf-8

import logging logging.basicConfig(level=logging.ERROR) class Student(object): '''

    >>> s = Student("iven",100)
    >>> s.info()
    iven 100
    >>> s.set_name(111)
    ERROR:root:this is not str!
    >>> s.set_score(222)
    ERROR:root:you input must in 0 ~ 100!
    >>> s.info()
    111 222
    '''
    def __init__(self,name,score):
            self.name = name
            self.score = score
    def info(self):
            print self.name,self.score

    def set_name(self,value):
            if not isinstance(value,str):
                    logging.error("this is not is str!")
            self.name = value

    def set_score(self,value):
            if not isinstance(value,int):
                    logging.error("not int!")
            if value < 0 or value > 100:
                    logging.error("you input must in 0 ~ 100!")
            self.score = value

if name == "main": import doctest doctest.testmod()

#不知道为什么,我的name和main都有下划线的,到这里显示的时候就变成没有下划线的了!


  • 1

Reply