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


Python IO.write方法代码示例

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


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

示例1: run

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def run(f: t.IO, out: t.IO = sys.stdout) -> None:
    r = csv.DictReader(f)
    rows = list(r)
    w = ColorfulWriter(out, fieldnames=list(rows[0].keys()))
    w.writeheader()
    w.writerows(rows)
    out.write(RESET)
开发者ID:podhmo,项目名称:individual-sandbox,代码行数:9,代码来源:00colorful.py

示例2: scrape_variables

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def scrape_variables(host: Text, logs_file: IO) -> None:
  br = mechanize.Browser()
  cj = cookielib.LWPCookieJar()
  br.set_cookiejar(cj)
  br.set_handle_equiv(True)
  # br.set_handle_gzip(True)
  br.set_handle_redirect(True)
  br.set_handle_referer(True)
  br.set_handle_robots(False)

  login_url = urlparse.urljoin(host, '/login')
  logging.info('Starting login into %s', login_url)
  response = br.open(login_url)
  br.form = next(iter(br.forms()))
  br.form['username'] = 'monitor'
  with open('../data/secret_key.txt') as f:
    br.form['password'] = f.read()
  br.method = 'POST'
  br.submit()
  br.method = 'GET'
  logging.info('Successfully logged into %s', login_url)

  variables_url = urlparse.urljoin(host, '/monitor/variables')
  while True:
    try:
      response = br.open(variables_url)
    except urllib2.URLError as e:
      logging.error('Could not open "%s": %s', variables_url, e)
      time.sleep(59 + random.random())
      continue
    raw_vars = response.read()
    logs_file.write(raw_vars)
    logs_file.write('\n')
    # variables = json.loads(raw_vars)
    time.sleep(59 + random.random())
开发者ID:mikelmcdaniel,项目名称:grade-oven,代码行数:37,代码来源:monitor.py

示例3: http_get

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def http_get(url: str, temp_file: IO) -> None:
    req = requests.get(url, stream=True)
    content_length = req.headers.get('Content-Length')
    total = int(content_length) if content_length is not None else None
    for chunk in req.iter_content(chunk_size=1024):
        if chunk: # filter out keep-alive new chunks
            temp_file.write(chunk)
开发者ID:DataTerminatorX,项目名称:NLP,代码行数:9,代码来源:file_cache.py

示例4: decode

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def decode(input: IO, output: IO) -> None:
    """Decode a file; input and output are binary files."""
    while True:
        line = input.readline()
        if not line:
            break
        s = binascii.a2b_base64(line)
        output.write(s)
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:10,代码来源:base64.py

示例5: _download_to_stream

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
    def _download_to_stream(self, blobname: str, stream: IO) -> bool:

        try:
            resource = self._azure_client.get_object(blobname)
        except ObjectDoesNotExistError:
            return False
        else:
            for chunk in resource.as_stream():
                stream.write(chunk)
            return True
开发者ID:OPWEN,项目名称:opwen-webapp,代码行数:12,代码来源:sync.py

示例6: http_get

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def http_get(url: str, temp_file: IO) -> None:
    req = requests.get(url, stream=True)
    content_length = req.headers.get('Content-Length')
    total = int(content_length) if content_length is not None else None
    progress = Tqdm.tqdm(unit="B", total=total)
    for chunk in req.iter_content(chunk_size=1024):
        if chunk: # filter out keep-alive new chunks
            progress.update(len(chunk))
            temp_file.write(chunk)
    progress.close()
开发者ID:apmoore1,项目名称:allennlp,代码行数:12,代码来源:file_utils.py

示例7: encode

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def encode(input: IO, output: IO) -> None:
    """Encode a file; input and output are binary files."""
    while True:
        s = input.read(MAXBINSIZE)
        if not s:
            break
        while len(s) < MAXBINSIZE:
            ns = input.read(MAXBINSIZE-len(s))
            if not ns:
                break
            s += ns
        line = binascii.b2a_base64(s)
        output.write(line)
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:15,代码来源:base64.py

示例8: pack

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
    def pack(self, out: IO):
        """
        Write the Field to the file-like object `out`.

        .. note::

            Advanced usage only. You will typically never need to call this
            method as it will be called for you when saving a ClassFile.

        :param out: Any file-like object providing `write()`
        """
        out.write(self.access_flags.pack())
        out.write(pack('>HH', self._name_index, self._descriptor_index))
        self.attributes.pack(out)
开发者ID:TkTech,项目名称:Jawa,代码行数:16,代码来源:fields.py

示例9: _print_truncate

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def _print_truncate(
    lines: Iterable,
    max_lines: int,
    outfile: IO,
) -> None:
    for i, line in enumerate(itertools.islice(lines, max_lines)):
        if i + 1 == max_lines:
            outfile.write('... (diff goes on) ...\n')
        else:
            outfile.write(line)
            if not line.endswith('\n'):
                outfile.write('<EOF>\n')
开发者ID:jma127,项目名称:pcu,代码行数:14,代码来源:runner.py

示例10: pack

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
    def pack(self, out: IO):
        """
        Write the AttributeTable to the file-like object `out`.

        .. note::

            Advanced usage only. You will typically never need to call this
            method as it will be called for you when saving a ClassFile.

        :param out: Any file-like object providing `write()`
        """
        out.write(pack('>H', len(self._table)))
        for attribute in self:
            info = attribute.pack()
            out.write(pack(
                '>HI',
                attribute.name.index,
                len(info)
            ))
            out.write(info)
开发者ID:TkTech,项目名称:Jawa,代码行数:22,代码来源:attribute.py

示例11: write_echo_json

# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import write [as 别名]
def write_echo_json(f: IO, obj: object) -> None:
    f.write("echo %s\n" % shlex.quote(json.dumps(obj)))
开发者ID:facebook,项目名称:hhvm,代码行数:4,代码来源:test_save_state.py


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