python 递归_python递归问题

importosdefsearch(s,path=os.path.abspath('.')):forzinos.listdir(path):ifos.path.isdir(z):print'Currnet:',pathpath2=os.path.join(path,z)print'future:',path2search(s,path2)...

import os

def search(s,path=os.path.abspath('.')):

for z in os.listdir(path):

if os.path.isdir(z):

print 'Currnet:',path

path2=os.path.join(path,z)

print 'future:',path2

search(s,path2)

elif os.path.isfile(z):

if s in z:

print os.path.join(path,z)

search(raw_input('Please enter a string:'))

执行结果:

PS D:\programfiles\python2.7> python err.py

Please enter a string:e

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\DLLs

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\Doc

D:\programfiles\python2.7\err.py

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\include

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\Lib

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\libs

D:\programfiles\python2.7\mydict_test.py

D:\programfiles\python2.7\mydict_test.pyc

D:\programfiles\python2.7\python.exe

D:\programfiles\python2.7\pythonw.exe

D:\programfiles\python2.7\Removepywin32.exe

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\Scripts

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\tcl

Crrunet: D:\programfiles\python2.7

fetural: D:\programfiles\python2.7\Tools

Crrunet: D:\programfiles\python2.7\Tools

fetural: D:\programfiles\python2.7\Tools\Scripts

D:\programfiles\python2.7\w9xpopen.exe

为什么search里面的search没能成功的执行?

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值