|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import os
- def my_dict(txt,count=0,my_dict={},dict_value=[]):
- for z in txt:
- count+=1
- if u_word in z:
- bg = z.find(u_word)
- while bg!=-1:
- dict_value.append(bg+1)
- bg = z.find(u_word,bg+1)
- my_dict[count] = dict_value
- keys = my_dict.keys()
- for o in keys:
- v = my_dict[o]
- print('关键字出现在%d行, 【%s】个位置'%o,v)
- def s_word(u_word,txt=[]):
- os.chdir(os.getcwd())
- for i in os.listdir(os.getcwd()):
- files = os.path.join(os.getcwd(),i)
- if os.path.isfile(files):
- first,end = os.path.splitext(files)
- if end == '.txt':
- with open(files) as f:
- if u_word in f.read():
- for each_line in f:
- txt.append(each_line) #txt是文本列表
- return txt
- else:
- s_word(files)
- os.chdir(os.pardir)
-
- word_user = input('请将该脚本放于带查找的文件夹呢,请输入关键字:')
- my_dict(s_word(word_user))
复制代码
总是报错达到最大深度,求大神看看哪错了
- RecursionError: maximum recursion depth exceeded in comparison
复制代码 |
|