Hi,

I just noticed (with numpy 1.7.1) that the following code

import numpy as np
np.savetxt('a.csv', [1], fmt=u'%.3f')

fails with:

   1045         else:
   1046             for row in X:
-> 1047                 fh.write(asbytes(format % tuple(row) + newline))
   1048         if len(footer) > 0:
   1049             footer = footer.replace('\n', '\n' + comments)

UnboundLocalError: local variable 'format' referenced before assignment

(of course, the simple solution is to remove the "u" prefix, but in my
real code, I have a "from __future__ import unicode_literals")

Since parts of the savetxt function were changed since that, I don't
know if this bug is still applicable or not.
I'm guessing that since Warren Weckesser commit
https://github.com/numpy/numpy/commit/0d284764a855cae11699228ff1b81e6d18f38ed2
the problem would be caught earlier with a much nicer ValueError.

However, I still see

isinstance(fmt, str): (on line 1035
https://github.com/numpy/numpy/blob/master/numpy/lib/npyio.py#L1035 )

How can I make the fmt argument work with unicode_literals ?

best,
Pierre



Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to