随笔分类 - Python
摘要:问题聚焦:熟悉getattr的应该知道,getattr(a, 'b')的作用就和a.b是一样的那么这个内建函数有什么作用呢,最方便的无疑是使用它来实现工厂方法(Factory Method)模式另外,在回调函数里也经常使用这个函数,对回调理解不深,这里不再举例 先看一下官方文档:getattr(object,name[,default])Return the value of the named attribute ofobject.namemust be a string. If the string is the name of one of the object’s at
阅读全文
摘要:算是第一个原创博客吧感觉蛮好的一个例子,makeTextFile.py中出现了错误,缩进不对,并且少了一句读入文件名的代码,现将修正后的代码贴出来供大家参考蛮喜欢python的风格的,功能也不错,这学期有用到的地方,所以就学了一下,大家一起努力吧~#!/usr/bin/env python'makeTextFile.py -- create text file'import osls = os.linesep# get filenamewhile True: fname = raw_input('Enter file name: ') #需要添加的语句,并且需要
阅读全文