当前位置: 首页>>代码示例>>Python>>正文


Python TextIO.readlines方法代码示例

本文整理汇总了Python中typing.TextIO.readlines方法的典型用法代码示例。如果您正苦于以下问题:Python TextIO.readlines方法的具体用法?Python TextIO.readlines怎么用?Python TextIO.readlines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在typing.TextIO的用法示例。


在下文中一共展示了TextIO.readlines方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import readlines [as 别名]
    def __init__(self, f: TextIO):
        """
        Create a new `PushbackFile` object to wrap a file-like object.

        **Parameters**

        - `f` (file-like object): A file-like object that contains both a
          `write()` method and a `flush()` method.
        """
        self.__buf = [c for c in ''.join(f.readlines())]
开发者ID:bmc,项目名称:grizzled-python,代码行数:12,代码来源:__init__.py

示例2: _search

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import readlines [as 别名]
    def _search(self, f: TextIO, filename: Optional[str] = None) -> bool:
        paragraph = []
        last_empty = False
        found = False
        eop_line = None

        def print_paragraph(paragraph: Sequence[str]) -> NoReturn:
            if self._print_file_header:
                print(f'::::::::::\n{filename}\n::::::::::\n')
                self._print_file_header = False
            print('\n'.join(paragraph))
            if self.print_eop and (eop_line is not None):
                print(eop_line)
            else:
                print()

        for line in f.readlines():
            if self.eop_regexp.match(line):
                # End of current paragraph, or a redundent (consecutive)
                # end-of-paragraph mark.  If it's truly the first one since
                # the end of the paragraph, search the accumulated lines of
                # the paragraph.

                if line[-1] == '\n':
                    eop_line = line[:-1]
                else:
                    eop_line = line

                if not last_empty:
                    last_empty = True
                    found = self._search_paragraph(paragraph)
                    if found:
                        print_paragraph(paragraph)
                    paragraph = []

            else:
                # Save this line in the current paragraph buffer
                if line[-1] == '\n':
                    line = line[:-1]
                paragraph += [line]
                last_empty = False

        # We might have a paragraph left in the buffer. If so, search it.

        if not last_empty:
            if self._search_paragraph(paragraph):
                found = True
                print_paragraph(paragraph)

        return found
开发者ID:bmc,项目名称:paragrep,代码行数:52,代码来源:__init__.py

示例3: load_profiles

# 需要导入模块: from typing import TextIO [as 别名]
# 或者: from typing.TextIO import readlines [as 别名]
def load_profiles(profiles_file: TextIO, person_to_friends: Dict[str, List[str]], \
                  person_to_networks: Dict[str, List[str]]) -> None:
    '''Update the person_to_friends dictionary and the person_to_networks
    dictionary to include data from profiles_file.

    '''
    user = none
    for l in profiles_file.readlines():
        if not user:
            user = to_user(l)
            create_key(user, person_to_friends)
            create_key(user, person_to_networks)
        else:
            if len(l.strip()) == 0:
                user = none
            elif ',' in l:
                person_to_friends[user].append(to_user(l))
            else:
                person_to_networks[user].append(l.strip())
开发者ID:mthomascomp,项目名称:Python-Assignments-,代码行数:21,代码来源:network_functions.py


注:本文中的typing.TextIO.readlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。