[Tutor] write dictionary to file

Walter Prins wprins at gmail.com
Fri Jun 20 14:45:34 CEST 2014


Hi,

Firstly an apology -- I only just noticed your original code was
Python 3 -- my example was Python 2, so there would be some changes
required to make the example work on Python 3...

On 20 June 2014 11:19, Ian D <duxbuz at hotmail.com> wrote:
> Thanks for your help
>
>
> I am not much closer in understanding this so I am going to try and start with a simpler example for myself.

Yes, that's usually a good idea.

> I will try and write some values to a file as I am struggling even doing this.
>
>
> TypeError: 'str' does not support the buffer interface
>
> TypeError: 'tuple' does not support the buffer interface

Could you post the lines of code that generates this exception and the
full stack trace that goes with it?

Nonetheless, having re-read your question and having googled a bit, it
seems that your problem might be related to Python 2 vs. Python 3, see
here:
http://stackoverflow.com/questions/24294457/python-typeerror-str-does-not-support-the-buffer-interface

In short: In Python 2 you are expected to open the CSV file in binary
mode ('wb').  In Python 3 this should be text mode as per the above
question, else you'll only be able to write "bytes" streams, hence the
"buffer" interface errors.  If you've perhaps been cribbing/using
Python 2.x examples and documentation while in fact using using Python
3, then that would help explain the confusion...?

Walter


More information about the Tutor mailing list