本文整理汇总了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)
示例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())
示例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)
示例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)
示例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
示例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()
示例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)
示例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)
示例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')
示例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)
示例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)))