美文网首页
重构典型案例

重构典型案例

作者: 唯此 | 来源:发表于2018-08-08 01:33 被阅读0次

2018-08-08

1.frm.unqiue()

for i in list(set(html_df['table_id'].values)):
for i in html_df['table_id'].unique()

2.正则表达式跨行搜索

        with open(py_file_path, 'r', encoding='utf-8') as f:
            file_codeline_list = f.readlines()
        for line in file_codeline_list: # todo: 可以简化
            if re.match(self.re_author, line):
                author = re.match(self.re_author, line).group(1)
                author = author.lstrip().rstrip()
                author = author.replace(self.DOUBLE_QUOTES, '').replace(self.SINGLE_QUOTES, '')
                return author
        return self.UNKNOW_AUTHOR
        re_author = r'\s*_author\s*=\s*"(\S+)"'
        assert isinstance(py_file_path, str)
        with open(py_file_path, 'r', encoding='utf-8') as f:
            all_text = f.read()
        res = re.search(re_author, all_text)
        if res:
            author = all_text[res.regs[1][0]: res.regs[1][1]]
            return author
        return self.UNKNOW_AUTHOR

3.迭代表达式

        with open(py_file_path, 'r', encoding='utf-8') as f:
            file_lines = f.readlines()
            striped_lines = []
        for line in file_lines:
            line = line.lstrip()  # 去除缩进
            if line != '':  # 跳过空白行
                striped_lines.append(line)
        return striped_lines
with open(py_file_path, 'r', encoding='utf-8') as f:
    file_lines = f.readlines()
striped_lines = [line.lstrip() for line in file_lines if line]

4.提取函数

事不过三,三则重构

        assert isinstance(author, str)
        assert isinstance(code_frm, pd.DataFrame)
        assert isinstance(title_num, str)
from helper import assert_isinstance # ylib里面提供易用的函数
assert_isinstance([author,code_frm,title_num ],[str, pd.DataFrame, str])

5.**Series传递函数参数

    def row_td_head(self, i, frm, td_head_list):
        upon_td_align = frm.loc[i, 'upon_td_align']
        upon_td_index = frm.loc[i, 'upon_td_index']
        row_align = frm.loc[i, 'row_align']
        col_index = frm.loc[i,'col_index']
        string = frm.loc[i, 'string']
        # 省略了N行代码
        return td_head

    def row_td_head(self, i, frm, td_head_list):
        def the_func(upon_td_align,upon_td_index,row_align,col_index,string):
            # 省略了N行代码
            return td_head
        return the_func(**frm.loc[i, ['upon_td_align','upon_td_index','row_align','col_index', 'string']])

cc利用1到5点改下代码.hj看下3到4.

相关文章

  • 重构典型案例

    2018-08-08 1.frm.unqiue() 2.正则表达式跨行搜索 3.迭代表达式 4.提取函数 事不过三...

  • 行为模式之Template Method 模式

    重构获得模式 Refactoring to Patterns 重构关键技巧 组件协昨模式 典型的模式 动机 M...

  • 典型案例

    伤官羊刃刀笔成名。羊刃见伤官文职。食伤合印老师校长。 袁世凯:乙 (食) 癸(杀) 丁 丁(比禄) ...

  • 结构思考力练习2一20161023

    作业一要求: 参考范例: 我的作答: 作业二要求:重构上周实践案例,画重构图 重构作答:

  • 2元致富梦你还会坚持吗?

    11月9日,中纪委网站发布了一个重磅文章:《减遏并重,标本兼治,重构福彩公信力,驻民政部纪检监察组从典型案例入手推...

  • 重构:读书笔记

    重构读书笔记 第一章 重构,第一个案例 第二章 重构原则 2.1 何为重构 重构(名词):对软件内部结构的一种调整...

  • 典型案例分享

    尊敬的各位领导,护理同仁们大家下午,我是职业病科的刘艳,今天我跟大家分享的是我和一位病人的故事…… 记得刚到职业病...

  • 《重构:改善既有代码的设计》读书笔记

    一,重构,第一个案例 这一章作者先用一个影片出租程序的案例,来演示重构的过程 每个Customer顾客可以租多部M...

  • 设计学员案例2019-03-19

    《重构学习体验》P 118设计学员案例 【I】[What]设计案例分析是编写案例材料,配合提问讨论的重要学员参与过...

  • PDCA典型案例分析

    合适的PDCA典型案例少之又少,本文案例来源与网络,筛选有效的的案例供大家学习和参考,希望对您的运营工作有所帮助,...

网友评论

      本文标题:重构典型案例

      本文链接:https://www.haomeiwen.com/subject/zogzvftx.html