Wait... WHAT?
Michael Torrie
torriem at gmail.com
Wed Feb 12 16:39:40 EST 2014
On 02/12/2014 01: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.
What happened? I'm not seeing any exception information. I do see code
that doesn't quite make sense.
> def save():
> target = open ("save.swroc", 'w')
> target.write([counter, loop, number_of_competitors, competitors])
Do you know what actually gets written? IE do you know what the
resulting text file looks like?
> 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]
This function isn't right. Question for you, what does open() return?
And if you assign that to "the_array," what makes you think you can
dereference open() as it it were an array? open() does not provide a
__getitem__() dunder method.
Python is pretty good at doing what you want usually, but you're missing
a step. Python's not bug-free, but the first suspect in a case like
this is your code.
There's an outside chance you want to explore the "pickle" module.
More information about the Python-list
mailing list