[issue17859] improve error message for saving ints to file

2016-04-16 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- resolution: -> duplicate stage: needs patch -> resolved status: open -> closed superseder: -> add "buffer protocol" to glossary ___ Python tracker

[issue17859] improve error message for saving ints to file

2016-04-16 Thread random832
random832 added the comment: This bug should be closed since #16518 was accepted and the error is now "TypeError: a bytes-like object is required, not 'int'" -- nosy: +random832 ___ Python tracker

[issue17859] improve error message for saving ints to file

2013-05-04 Thread Ezio Melotti
Ezio Melotti added the comment: > binary-mode write requires bytes-like object, not 'int' Looks like the function that raises the error (Objects/abstract.c:352) doesn't have enough information to produce a message like that. I attached a patch to #16518 that improves this and other error messag

[issue17859] improve error message for saving ints to file

2013-05-03 Thread Terry J. Reedy
Terry J. Reedy added the comment: I think the point is that the error message does not make much sense unless one knows a) that the file is open in binary mode (and that could have happened in a different file) and b) that 'does not support the buffer interface' means 'is not a bytes-like obje

[issue17859] improve error message for saving ints to file

2013-05-03 Thread Éric Araujo
Éric Araujo added the comment: Ah, right, I missed the part about the file being opened in binary mode. -- ___ Python tracker ___ ___

[issue17859] improve error message for saving ints to file

2013-04-28 Thread R. David Murray
R. David Murray added the comment: Éric, print doesn't help if one is writing binary data. What do you mean by not understanding the first message? If you are agreeing that the first error message in Anatoly's initial post isn't clear, does Ezio's proposed change make it clearer? -

[issue17859] improve error message for saving ints to file

2013-04-28 Thread Éric Araujo
Éric Araujo added the comment: I don’t understand that the first message says. If one wants to call the write method of a file object opened in binary mode, one needs to pass bytes, as the doc surely explains. The same error that is seen here with ints would be seen with any other objects. A

[issue17859] improve error message for saving ints to file

2013-04-28 Thread Ezio Melotti
Ezio Melotti added the comment: Maybe the error could be replaced with something like: TypeError: write() requires an object that supports the buffer interface, not '' But that's a bit long and also not entirely accurate, because the type accepted by write depends on the type of the file (bina

[issue17859] improve error message for saving ints to file

2013-04-28 Thread anatoly techtonik
New submission from anatoly techtonik: I needed to write some bytes to file and got this message. >>> hex = open('hex', 'wb') >>> for x in range(0, 0xff, 0x11): ... hex.write(x) ... Traceback (most recent call last): File "", line 2, in TypeError: 'int' does not support the buffer interface