@@ -816,7 +816,7 @@ def fromstring(datastring, dtype=None, shape=None, offset=0, formats=None,
816
816
817
817
>>> s = '\x01\x02\x03abc'
818
818
>>> np.core.records.fromstring(s, dtype='u1,u1,u1,S3')
819
- Traceback (most recent call last)
819
+ Traceback (most recent call last):
820
820
...
821
821
TypeError: a bytes-like object is required, not 'str'
822
822
"""
@@ -881,18 +881,21 @@ def fromfile(fd, dtype=None, shape=None, offset=0, formats=None,
881
881
>>> from tempfile import TemporaryFile
882
882
>>> a = np.empty(10,dtype='f8,i4,a5')
883
883
>>> a[5] = (0.5,10,'abcde')
884
- >>>
885
- >>> fd=TemporaryFile()
886
- >>> a = a.newbyteorder('<')
887
- >>> a.tofile(fd)
888
- >>>
889
- >>> _ = fd.seek(0)
890
- >>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
891
- ... byteorder='<')
884
+
885
+ Save and load from a temporary file enforcing a little endian byte-order.
886
+
887
+ >>> with TemporaryFile() as fd:
888
+ ... a = a.newbyteorder('<')
889
+ ... a.tofile(fd)
890
+ ...
891
+ ... _ = fd.seek(0)
892
+ ... r = np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,
893
+ ... byteorder='<')
892
894
>>> print(r[5])
893
895
(0.5, 10, 'abcde')
894
896
>>> r.shape
895
897
(10,)
898
+
896
899
"""
897
900
898
901
if dtype is None and formats is None :
0 commit comments