當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。