本文整理匯總了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())