文档提取函数格式

with open("word.txt",'r') as f:                                 # 打开文件
    new_file_list=[]
    for line in f.readlines():                                  # 遍历文件行,并切片
        if line!='\n':
            line_list=line.split()
            if line_list[0]=='def':

                for list_ob in line_list:                        # 遍历单词块,将需要部分插入列表
                    if list_ob=='#':
                        break                             # 'aaaddddffff'[2:6]!!!!!!!!
                    if list_ob!='def':
                        new_file_list.append(list_ob)
                        new_file_list.append(' ')
                new_file_list.append('\n\n\n')


with open('nword.txt','w') as f:
    for ob in new_file_list:                                      # 遍历列表,写入新文档
        f.write(ob)

文档:

def format(self, *args, **kwargs): # known special case of str.format
"""
S.format(*args, **kwargs) -> str

Return a formatted version of S, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}').
"""
pass

def format_map(self, mapping): # real signature unknown; restored from __doc__
"""
S.format_map(mapping) -> str

Return a formatted version of S, using substitutions from mapping.
The substitutions are identified by braces ('{' and '}').
"""
return ""

def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
"""
S.index(sub[, start[, end]]) -> int

Like S.find() but raise ValueError when the substring is not found.
"""
return 0

新文档:

format(self, *args, **kwargs):


format_map(self, mapping):


index(self, sub, start=None, end=None):

 

posted @ 2017-09-13 05:28  明宣  阅读(147)  评论(0)    收藏  举报