1.多继承
class A(object):
def fly(self):
print 'fly'
class B(object):
@staticmethod
def sleep():
print 'sleep'
class C(A, B):
pass
p = C()
p.fly()
这个里和java不同的是java是单继承,python是多重继成
2.日志打印
import logginglogging.basicConfig(level=logging.INFO)class A(object): def fly(self): logging.info('fly')class B(object): @staticmethod def sleep(): print 'sleep'class C(A, B): passp = C()p.fly()
3.读取本地文件
try: f = open('C:\\Users\\Administrator\Desktop\\remind.txt', 'r')
print f.read().decode("gbk")
finally:
f.close()
写文件
try: f = open('C:\\Users\\Administrator\Desktop\\remind.txt', 'w')
print f.write('haha我是都比')
finally: f.close()