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


Python io.TextIO方法代码示例

本文整理汇总了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) 
开发者ID:larsyencken,项目名称:csvdiff,代码行数:24,代码来源:__init__.py

示例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 
开发者ID:geospace-code,项目名称:georinex,代码行数:22,代码来源:rio.py

示例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 
开发者ID:geospace-code,项目名称:georinex,代码行数:20,代码来源:obs2.py

示例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 
开发者ID:geospace-code,项目名称:georinex,代码行数:27,代码来源:obs2.py

示例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 
开发者ID:geospace-code,项目名称:georinex,代码行数:22,代码来源:hatanaka.py

示例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) 
开发者ID:geospace-code,项目名称:georinex,代码行数:21,代码来源:nav3.py

示例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 
开发者ID:geospace-code,项目名称:georinex,代码行数:19,代码来源:nav2.py

示例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) 
开发者ID:geospace-code,项目名称:georinex,代码行数:25,代码来源:nav2.py

示例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 
开发者ID:geospace-code,项目名称:georinex,代码行数:19,代码来源:obs3.py

示例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] 
开发者ID:BlackLight,项目名称:platypush,代码行数:19,代码来源:csv.py

示例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) 
开发者ID:larsyencken,项目名称:csvdiff,代码行数:7,代码来源:records.py

示例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) 
开发者ID:larsyencken,项目名称:csvdiff,代码行数:7,代码来源:records.py

示例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 
开发者ID:boolangery,项目名称:py-lua-parser,代码行数:8,代码来源:LuaLexer.py

示例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# 
开发者ID:hao-lee,项目名称:Graphvizer,代码行数:33,代码来源:Parser.py

示例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 
开发者ID:hao-lee,项目名称:Graphvizer,代码行数:8,代码来源:DOTLexer.py


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