鱼C论坛

 找回密码
 立即注册
查看: 2067|回复: 5

35讲课后题第四个报错 哪个大神给看下

[复制链接]
发表于 2017-10-17 19:46:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Traceback (most recent call last):
  File "D:/检测你的代码量.py", line 52, in <module>
    search_file(path)
  File "D:/检测你的代码量.py", line 45, in search_file
    search_file(each_file)
  File "D:/检测你的代码量.py", line 45, in search_file
    search_file(each_file)
  File "D:/检测你的代码量.py", line 45, in search_file
    search_file(each_file)
  [Previous line repeated 987 more times]
  File "D:/检测你的代码量.py", line 32, in search_file
    ext=os.path.splitext(each_file)[1]
  File "C:\Users\Joshua\AppData\Local\Programs\Python\Python36\lib\ntpath.py", line 227, in splitext
    return genericpath._splitext(p, '\\', '/', '.')
  File "C:\Users\Joshua\AppData\Local\Programs\Python\Python36\lib\genericpath.py", line 127, in _splitext
    sepIndex = max(sepIndex, altsepIndex)
RecursionError: maximum recursion depth exceeded in comparison
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2017-10-17 19:47:49 | 显示全部楼层
代码来了 是这样 #_*_coding:utf-8_*_
import easygui as g
import os
#import sys
#sys.setrecursionlimit(10000)

def show_result(start_dir):
    lines=0
    total=0
    text = ""
    for i in source_list:
        lines=source_list[i]
        total+=lines
        text += "【%s】源文件%d个,源代码%d行\n" % (i,file_list[i], lines)
    title = "统计结果"
    msg = "您目前已编写%d行代码,完成进度%.2f %%\n,离十万行代码还差%d行" % (total, total / 1000, 100000 - total)
    g.textbox(msg, title, text)
def calc_code(file_name):
    lines=0
    with open(file_name,"rb") as f:
        print("正在分析文件:%s..."%file_name)
        try:
            for each_line in f:
                lines+=1
        except UnicodeDecodeError:
            pass
    return lines

def search_file(start_dir):
    os.chdir(os.curdir)
    for each_file in os.listdir(os.curdir):
        ext=os.path.splitext(each_file)[1]

        if ext in target:
            lines=calc_code(each_file)
            try:
                file_list[ext]+=1
            except KeyError:
                file_list[ext]=1
            try:
                source_list[ext]+=lines
            except KeyError:
                source_list[ext]=lines
        if os.path.isdir(each_file):
            search_file(each_file)
            os.chdir(os.pardir)


target=['.py']
file_list={}
source_list={}
g.msgbox("请打开您存放所有代码的文件夹.....","统计代码量")
path=g.diropenbox("请选择您的代码库:")
search_file(path)
show_result(path)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-17 20:32:24 | 显示全部楼层
  1. import sys  
  2.   
  3. sys.setrecursionlimit(1000000)
复制代码

显然一万是不够的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-17 20:45:34 | 显示全部楼层

100万   哥  
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-17 21:21:25 | 显示全部楼层

所以可以吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-17 22:57:53 | 显示全部楼层

不可以  把递归调用注释掉 不报错了 可以正常运行了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-24 11:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表