Wait... WHAT?

Ian Kelly ian.g.kelly at gmail.com
Wed Feb 12 22:35:18 CET 2014

On Wed, Feb 12, 2014 at 1:21 PM,  <eneskristo at gmail.com> wrote:
> I think of it as a bit strange. Should I report it as a bug? I was trying to incorporate a save/load, and this happened.
>     def save():
>         target = open ("save.swroc", 'w')
>         target.write([counter, loop, number_of_competitors, competitors])
>     def load():
>         target = open("save.swroc", 'r')
>         the_array = target
>         counter = the_array[0]
>         loop = the_array[1]
>         number_of_competitors = the_array[2]
>         competitors = the_array[3]
> Swroc is an nonexisting file format that i just made up, an acronym of the program

You can't write lists directly to files.  You can only write strings
to files.  To write and read a list, you'll need to first serialize it
and later deserialize it.  Your needs appear simple enough that I
suggest the json module for this.

    json.dump([counter, loop, number_of_competitors, competitors], target)

    [counter, loop, number_of_competitors, competitors] = json.load(target)

It sounds like this may be the source of the exception that tkinter
was trying unsuccessfully to report in your first post.  You should
still fix your sys.stderr so that tkinter can report exceptions.

More information about the Python-list mailing list