MCPcopy Create free account
hub / github.com/numpy/numpy / WriteWrap

Class WriteWrap

numpy/lib/npyio.py:1518–1549  ·  view source on GitHub ↗

Convert to bytes on bytestream inputs.

Source from the content-addressed store, hash-verified

1516 delimiter = asstr(delimiter)
1517
1518 class WriteWrap:
1519 """Convert to bytes on bytestream inputs.
1520
1521 """
1522 def __init__(self, fh, encoding):
1523 self.fh = fh
1524 self.encoding = encoding
1525 self.do_write = self.first_write
1526
1527 def close(self):
1528 self.fh.close()
1529
1530 def write(self, v):
1531 self.do_write(v)
1532
1533 def write_bytes(self, v):
1534 if isinstance(v, bytes):
1535 self.fh.write(v)
1536 else:
1537 self.fh.write(v.encode(self.encoding))
1538
1539 def write_normal(self, v):
1540 self.fh.write(asunicode(v))
1541
1542 def first_write(self, v):
1543 try:
1544 self.write_normal(v)
1545 self.write = self.write_normal
1546 except TypeError:
1547 # input is probably a bytestream
1548 self.write_bytes(v)
1549 self.write = self.write_bytes
1550
1551 own_fh = False
1552 if isinstance(fname, os_PathLike):

Callers 1

savetxtFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected