软件工程第一次作业

 

 

要求0:作业要求地址:https://edu.cnblogs.com/campus/nenu/2016CS/homework/2110

要求1:git仓库地址https://git.coding.net/wishsama/wf.git

要求2:

PSP阶段 预计时间 实际时间
计划 30 20
明确需求和其他相关因素,估计每段时间成本 30 20
开发 300 400
需求分析 0 0
生成设计文档 0 0
设计复审(和同学审核设计文档) 0 0
代码规范(为目前的开发制定合适的规范 0 0
具体设计 0 0
具体编码 300 400
代码复审 0 0
测试(自测、修改代码、提交修改) 20 30
报告 20 30
事后总结 20 30

 

 

用split函数和正则表达式分割字符串计算词频,用正则表达式判断词是否合法

def processLine(line, wordCounts):
    words=[]
    words.extend(re.split('\W', line))
    for word in words:
        if isLegal(word):
            if word in wordCounts:
                wordCounts[word] += 1
            else:
                wordCounts[word] = 1
    return wordCounts


def isLegal(word):
    return re.match("^[a-zA-Z][a-zA-Z0-9]*$", word)

 

 

参数为文件夹名时先得到文件夹中txt文件名

def IsSubString(SubStrList, Str):

    flag = True
    for substr in SubStrList:
        if not (substr in Str):
            flag = False
    return flag


def GetFileList(FindPath, FlagStr=["txt"]):

    FileList = []
    FileNames = os.listdir(FindPath)
    if (len(FileNames) > 0):
        for fn in FileNames:
            if (len(FlagStr) > 0):
                # 返回指定类型的文件名
                if (IsSubString(FlagStr, fn)):
                    fullfilename = os.path.join(FindPath, fn)
                    FileList.append(fullfilename)
            else:
                # 默认直接返回所有文件名
                fullfilename = os.path.join(FindPath, fn)
                FileList.append(fullfilename)
    # 对文件名排序
    if (len(FileList) > 0):
        FileList.sort()

    return FileList

 

 

 argparse解析控制台参数

    parser = argparse.ArgumentParser()
    parser.add_argument('-c', default="", help=help)
    parser.add_argument('-f', default="", help=help)
    parser.add_argument('-n', default="", help=help)
    args = parser.parse_args()

 

功能1:

 

功能2:

 

功能3:

 

 心路历程:

  听说python方便就用了,边做边学,学了些python的模块。

  

 

posted @ 2018-09-21 21:43  wishsama  阅读(163)  评论(1编辑  收藏  举报