本文整理匯總了Python中typing.io.TextIO方法的典型用法代碼示例。如果您正苦於以下問題:Python io.TextIO方法的具體用法?Python io.TextIO怎麽用?Python io.TextIO使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類typing.io
的用法示例。
在下文中一共展示了io.TextIO方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: patch_file
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def patch_file(patch_stream: TextIO, fromcsv_stream: TextIO, tocsv_stream: TextIO,
strict: bool = True, sep: str = ','):
"""
Apply the patch to the source CSV file, and save the result to the target
file.
"""
diff = patch.load(patch_stream)
from_records = records.load(fromcsv_stream, sep=sep)
to_records = patch.apply(diff, from_records, strict=strict)
# what order should the columns be in?
if to_records:
# have data, use a nice ordering
all_columns = to_records[0].keys()
index_columns = diff['_index']
fieldnames = _nice_fieldnames(all_columns, index_columns)
else:
# no data, use the original order
fieldnames = from_records.fieldnames
records.save(to_records, fieldnames, tocsv_stream)
示例2: first_nonblank_line
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def first_nonblank_line(f: TextIO, max_lines: int = 10) -> str:
""" return first non-blank 80 character line in file
Parameters
----------
max_lines: int
maximum number of blank lines
"""
line = ""
for _i in range(max_lines):
line = f.readline(81)
if line.strip():
break
if _i == max_lines - 1 or not line:
raise ValueError(f"could not find first valid header line in {f.name}")
return line
示例3: _getsvind
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def _getsvind(f: TextIO, ln: str) -> List[str]:
if len(ln) < 32:
raise ValueError(f'satellite index line truncated: {ln}')
Nsv = int(ln[29:32]) # Number of visible satellites this time %i3
# get first 12 SV ID's
sv = _getSVlist(ln, min(12, Nsv), [])
# any more SVs?
n = Nsv-12
while n > 0:
sv = _getSVlist(f.readline(), min(12, n), sv)
n -= 12
if Nsv != len(sv):
raise ValueError('satellite list read incorrectly')
return sv
示例4: obstime2
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def obstime2(fn: Union[TextIO, Path],
verbose: bool = False) -> np.ndarray:
"""
read all times in RINEX2 OBS file
"""
times = []
with opener(fn) as f:
# Capture header info
hdr = obsheader2(f)
for ln in f:
try:
time_epoch = _timeobs(ln)
except ValueError:
continue
times.append(time_epoch)
_skip(f, ln, hdr['Nl_sv'])
times = np.asarray(times)
check_unique_times(times)
return times
示例5: opencrx
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def opencrx(f: TextIO) -> str:
"""
Conversion to string is necessary because of a quirk where gzip.open() even with 'rt' doesn't decompress until read.
Nbytes is used to read first line.
"""
exe = crxexe()
if not exe:
if build() != 0:
raise RuntimeError('could not build Hatanka converter. Do you have a C compiler?')
exe = crxexe()
if not exe:
raise RuntimeError('Hatanaka converter is broken or missing.')
ret = subprocess.check_output([exe, '-'],
input=f.read(),
universal_newlines=True)
return ret
示例6: navtime3
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def navtime3(fn: Union[TextIO, Path]) -> np.ndarray:
"""
return all times in RINEX file
"""
times = []
with opener(fn) as f:
navheader3(f) # skip header
for line in f:
try:
time = _time(line)
except ValueError:
continue
times.append(time)
_skip(f, Nl[line[0]]) # different system types skip different line counts
return np.unique(times)
示例7: navheader2
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def navheader2(f: TextIO) -> Dict[str, Any]:
"""
For RINEX NAV version 2 only. End users should use rinexheader()
"""
if isinstance(f, (str, Path)):
with opener(f, header=True) as h:
return navheader2(h)
hdr = rinexinfo(f)
for ln in f:
if 'END OF HEADER' in ln:
break
kind, content = ln[60:].strip(), ln[:60]
hdr[kind] = content
return hdr
示例8: navtime2
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def navtime2(fn: Union[TextIO, Path]) -> np.ndarray:
"""
read all times in RINEX 2 NAV file
"""
times = []
with opener(fn) as f:
hdr = navheader2(f)
while True:
ln = f.readline()
if not ln:
break
try:
time = _timenav(ln)
except ValueError:
continue
times.append(time)
_skip(f, Nl[hdr['systems']])
return np.unique(times)
示例9: obstime3
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def obstime3(fn: Union[TextIO, Path],
verbose: bool = False) -> np.ndarray:
"""
return all times in RINEX file
"""
times = []
with opener(fn) as f:
for ln in f:
if ln.startswith('>'):
times.append(_timeobs(ln))
times = np.asarray(times)
check_unique_times(times)
return times
示例10: lines
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def lines(cls, f: TextIO, reverse: bool = False):
if not reverse:
for line in f:
yield line
else:
part = ''
quoting = False
for block in cls.reversed_blocks(f):
for c in reversed(block):
if c == '"':
quoting = not quoting
elif c == '\n' and part and not quoting:
yield part[::-1]
part = ''
part += c
if part:
yield part[::-1]
示例11: __init__
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def __init__(self, istream: TextIO, sep: str = ',') -> None:
# bump the built-in limits on field sizes
csv.field_size_limit(2**24)
self.reader = csv.DictReader(istream, delimiter=sep)
示例12: save
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def save(records: Sequence[Record], fieldnames: List[Column], ostream: TextIO):
writer = csv.DictWriter(ostream, fieldnames)
writer.writeheader()
for r in records:
writer.writerow(r)
示例13: __init__
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def __init__(self, input=None, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.7.1")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None
示例14: __init__
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
super().__init__()
# The input stream.
self._input = None
self._output = output
# The error handling strategy for the parser. The default value is a new
# instance of {@link DefaultErrorStrategy}.
self._errHandler = DefaultErrorStrategy()
self._precedenceStack = list()
self._precedenceStack.append(0)
# The {@link ParserRuleContext} object for the currently executing rule.
# self is always non-null during the parsing process.
self._ctx = None
# Specifies whether or not the parser should construct a parse tree during
# the parsing process. The default value is {@code true}.
self.buildParseTrees = True
# When {@link #setTrace}{@code (true)} is called, a reference to the
# {@link TraceListener} is stored here so it can be easily removed in a
# later call to {@link #setTrace}{@code (false)}. The listener itself is
# implemented as a parser listener so self field is not directly used by
# other parser methods.
self._tracer = None
# The list of {@link ParseTreeListener} listeners registered to receive
# events during the parse.
self._parseListeners = None
# The number of syntax errors reported during parsing. self value is
# incremented each time {@link #notifyErrorListeners} is called.
self._syntaxErrors = 0
self.setInputStream(input)
# reset the parser's state#
示例15: __init__
# 需要導入模塊: from typing import io [as 別名]
# 或者: from typing.io import TextIO [as 別名]
def __init__(self, input=None, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.8")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None