首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python,一个for循环语句调用有关问题,请问

2013-07-04 
python,一个for循环语句调用问题,请教find函数里为什么写成startdiros.curdir?函数调用时,startdir到底是

python,一个for循环语句调用问题,请教
find函数里为什么写成startdir=os.curdir?

函数调用时,startdir到底是等于self.dirpath.GetValue()还是os.curdir?

self.find(self.filename.GetValue(),self.dirpath.GetValue())
def find(self,pattern,startdir=os.curdir):
            for (thisdir, subdirs,fileshere) in os.walk(startdir):
                    for filename in fileshere:
                            if fnmatch.fnmatch(filename, pattern):
                                    fullpatch = os.path.join(thisdir, filename)
                                    self.matches.append(fullpatch) Python
[解决办法]
startdir=os.curdir 这是默认设定
就是说你不传入startdir参数(省略)时就默认使用os.curdir,但如果传入,就使用所传入的值

例如
def abc(a, b=0):
    print(a, ',', b)

abc(1,2) 得到 1,2
abc(1) 得到 1,0

热点排行