Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66264

Re: Wait... WHAT?

Date 2014-02-13 15:22 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Wait... WHAT?
References (5 earlier) <20140212184432.1df9b491@bigbox.christie.dr> <ldh5cr$bdk$1@ger.gmane.org> <20140212212953.458b810a@bigbox.christie.dr> <mailman.6821.1392263231.18130.python-list@python.org> <8778c4cc-334b-4254-aed7-0f33acbf1d8f@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.6897.1392330215.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 02/13/2014 10:46 AM, eneskristo@gmail.com wrote:
> Can we please revert back to the original problem?
>     def save():
>         target = open ("save.swroc", 'w')
>         target.write([counter, loop, number_of_competitors, competitors])
                      ^^^^^^^^^
Have you tried to run this code?  Does it even produce a file?  On my
python it says that write() is expecting a string on Python 3, or a
character buffer object on Python 2.7.  Have you broken out the code
into a minimal, standalone file you can work on?

>     def load():
>         the_array = list(open("save.swroc", 'r'))
                  ^^^^^^^^^^^
That's better.  You know it reads in the text file one line at a time
into a list right?  This would work if your file was actually written
with one variable in text form on each line.

>         the_array = target
		    ^^^^^^^^^^
You have now reassigned the_array to an undefined object. If target is
defined somewhere (I can't see that it is here in your code snippet),
then you've now lost the array of lines you just read in.

>         counter = the_array[0]
>         loop = the_array[1]
>         number_of_competitors = the_array[2]
>         competitors = the_array[3]
> Is this better?

Well it doesn't run, so we can't say it's better.

A couple of points/questions/hints/suggestions:

1. make a minimal, complete, example of what you are trying to do.  Code
you can run without the rest of your program.

2. What are your variables, "counter," "loop," "number_of_competitors,"
"competitors?"

3. What format is the file supposed to be in?

4. If you pullup the file in an editor does it look right? (IE do you
know what the output from your save function actually looks like?)

5. If you're dealing with numbers, remember the text file has no concept
of numbers. You'll have to parse them from text when you read them.

6. Consider using the pickle module if you really want to store and load
python objects without encoding and decoding a text file.

Hope this helps.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Wait... WHAT? eneskristo@gmail.com - 2014-02-12 11:43 -0800
  Re: Wait... WHAT? Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-12 13:13 -0700
  Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-12 12:21 -0800
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 20:38 +0000
    Re: Wait... WHAT? Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-12 14:35 -0700
    Re: Wait... WHAT? Michael Torrie <torriem@gmail.com> - 2014-02-12 14:39 -0700
    Re: Wait... WHAT? Tim Chase <python.list@tim.thechases.com> - 2014-02-12 16:14 -0600
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 23:36 +0000
    Re: Wait... WHAT? Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-12 17:01 -0700
    Re: Wait... WHAT? Tim Chase <python.list@tim.thechases.com> - 2014-02-12 18:44 -0600
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-13 00:59 +0000
    Re: Wait... WHAT? Chris Angelico <rosuav@gmail.com> - 2014-02-13 12:10 +1100
    Re: Wait... WHAT? Tim Chase <python.list@tim.thechases.com> - 2014-02-12 21:29 -0600
    Re: Wait... WHAT? Chris Angelico <rosuav@gmail.com> - 2014-02-13 14:47 +1100
      Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-13 09:46 -0800
        Re: Wait... WHAT? MRAB <python@mrabarnett.plus.com> - 2014-02-13 18:25 +0000
        Re: Wait... WHAT? Michael Torrie <torriem@gmail.com> - 2014-02-13 15:22 -0700
  Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-12 12:43 -0800
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 20:56 +0000
      Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-12 12:59 -0800
        Re: Wait... WHAT? Chris Angelico <rosuav@gmail.com> - 2014-02-13 08:17 +1100
        Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 21:23 +0000
    Re: Wait... WHAT? Grant Edwards <invalid@invalid.invalid> - 2014-02-12 23:09 +0000

csiph-web