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


Groups > comp.lang.python > #66199

Re: Wait... WHAT?

Date 2014-02-13 18:25 +0000
From MRAB <python@mrabarnett.plus.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.6851.1392315919.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-02-13 17:46, eneskristo@gmail.com wrote:
> Can we please revert back to the original problem?
>      def save():
 >          target = open ("save.swroc", 'w')

This opens the file for writing text (assuming you're using Python 3).

 >          target.write([counter, loop, number_of_competitors, 
competitors])

This tries to write a list to the file. You can't do that. A list isn't
text.

>      def load():
>          the_array = list(open("save.swroc", 'r'))

This open the file for reading text. Using 'list' will make it read
lines of text and return them as a list.

>          the_array = target

What's 'target'?

>          counter = the_array[0]

This will set 'counter' to the first line of text that was read.

>          loop = the_array[1]

This will set 'loop' to the second line of text.

>          number_of_competitors = the_array[2]

This will set 'number_of_competitors' to the third line of text.

>          competitors = the_array[3]

This will set 'number_of_competitors' to the fourth line of text.

> Is this better?
>
Not really! :-)

Have a look at the "pickle" module, or the "json" module.

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