diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-02-20 18:12:29 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-02-20 18:12:29 +0000 |
commit | cb8c9b33c94d078e56e5ffaf22061aeab317d3a1 (patch) | |
tree | d8add9fdc170abe3548cb9290929b410a9c37a75 /numpy/lib/format.py | |
parent | f8401465c6b5876c57d3908e38ca37c39695033f (diff) | |
download | numpy-cb8c9b33c94d078e56e5ffaf22061aeab317d3a1.tar.gz |
3K: lib: bytes vs. str fixes in lib.format and lib.io
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r-- | numpy/lib/format.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index a28108f5f..520c6bd25 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -141,7 +141,7 @@ import numpy from numpy.lib.utils import safe_eval from numpy.compat import asbytes, isfileobj -MAGIC_PREFIX = '\x93NUMPY' +MAGIC_PREFIX = asbytes('\x93NUMPY') MAGIC_LEN = len(MAGIC_PREFIX) + 2 def magic(major, minor): @@ -164,7 +164,7 @@ def magic(major, minor): raise ValueError("major version must be 0 <= major < 256") if minor < 0 or minor > 255: raise ValueError("minor version must be 0 <= minor < 256") - return '%s%s%s' % (MAGIC_PREFIX, chr(major), chr(minor)) + return asbytes('%s%s%s' % (MAGIC_PREFIX, chr(major), chr(minor))) def read_magic(fp): """ Read the magic string to get the version of the file format. @@ -271,12 +271,12 @@ def write_array_header_1_0(fp, d): # advantage of our premature optimization. current_header_len = MAGIC_LEN + 2 + len(header) + 1 # 1 for the newline topad = 16 - (current_header_len % 16) - header = '%s%s\n' % (header, ' '*topad) + header = asbytes('%s%s\n' % (header, ' '*topad)) if len(header) >= (256*256): raise ValueError("header does not fit inside %s bytes" % (256*256)) header_len_str = struct.pack('<H', len(header)) fp.write(header_len_str) - fp.write(asbytes(header)) + fp.write(header) def read_array_header_1_0(fp): """ |