MCPcopy Index your code
hub / github.com/numpy/numpy / WriteWrap

Class WriteWrap

numpy/lib/_npyio_impl.py:1511–1542  ·  view source on GitHub ↗

Convert to bytes on bytestream inputs.

Source from the content-addressed store, hash-verified

1509 """
1510
1511 class WriteWrap:
1512 """Convert to bytes on bytestream inputs.
1513
1514 """
1515 def __init__(self, fh, encoding):
1516 self.fh = fh
1517 self.encoding = encoding
1518 self.do_write = self.first_write
1519
1520 def close(self):
1521 self.fh.close()
1522
1523 def write(self, v):
1524 self.do_write(v)
1525
1526 def write_bytes(self, v):
1527 if isinstance(v, bytes):
1528 self.fh.write(v)
1529 else:
1530 self.fh.write(v.encode(self.encoding))
1531
1532 def write_normal(self, v):
1533 self.fh.write(asunicode(v))
1534
1535 def first_write(self, v):
1536 try:
1537 self.write_normal(v)
1538 self.write = self.write_normal
1539 except TypeError:
1540 # input is probably a bytestream
1541 self.write_bytes(v)
1542 self.write = self.write_bytes
1543
1544 own_fh = False
1545 if isinstance(fname, os.PathLike):

Callers 1

savetxtFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…