diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2008-05-14 12:51:23 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2008-05-14 12:51:23 +0000 |
commit | b12d0784116d7740a4ce3be18925d0cf7e7db5df (patch) | |
tree | c27cd7dd42379f800f681333ddd3f0e52eb3b4d5 /numpy/lib/io.py | |
parent | 7407ae44ee73f1da902fdc87c496bfc8141a3132 (diff) | |
download | numpy-b12d0784116d7740a4ce3be18925d0cf7e7db5df.tar.gz |
Merge docstrings from wiki.
Diffstat (limited to 'numpy/lib/io.py')
-rw-r--r-- | numpy/lib/io.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/numpy/lib/io.py b/numpy/lib/io.py index 709a2445a..dce462ac7 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -428,7 +428,9 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): import re def fromregex(file, regexp, dtype): - """Construct an array from a text file, using regular-expressions parsing. + """ + Construct a record array from a text file, using + regular-expressions parsing. Array is constructed from all matches of the regular expression in the file. Groups in the regular expression are converted to fields. @@ -436,19 +438,20 @@ def fromregex(file, regexp, dtype): Parameters ---------- file : str or file - File name or file object to read + File name or file object to read. regexp : str or regexp - Regular expression to use to parse the file + Regular expression used to parse the file. + Groups in the regular expression correspond to fields in the dtype. dtype : dtype or dtype list Dtype for the structured array - Example - ------- - >>> import numpy as np + Examples + -------- >>> f = open('test.dat', 'w') - >>> f.write("1312 foo\n1534 bar\n 444 qux") + >>> f.write("1312 foo\\n1534 bar\\n444 qux") >>> f.close() - >>> np.fromregex('test.dat', r"(\d+)\s+(...)", [('num', np.int64), ('key', 'S3')]) + >>> np.fromregex('test.dat', r"(\\d+)\\s+(...)", + ... [('num', np.int64), ('key', 'S3')]) array([(1312L, 'foo'), (1534L, 'bar'), (444L, 'qux')], dtype=[('num', '<i8'), ('key', '|S3')]) |