本文整理汇总了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())]
示例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
示例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())