Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'broken': 0.04; 'encoding': 0.05; 'output': 0.05; 'problem?': 0.07; 'string': 0.09; 'run,': 0.09; 'undefined': 0.09; 'python': 0.11; 'def': 0.12; "'w')": 0.16; 'better?': 0.16; 'code?': 0.16; 'competitors': 0.16; 'expecting': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'helps.': 0.16; 'variables,': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'variable': 0.18; 'module': 0.19; 'trying': 0.19; 'written': 0.21; 'example': 0.22; 'load': 0.23; 'header:User- Agent:1': 0.23; 'parse': 0.24; 'file.': 0.24; 'looks': 0.24; 'somewhere': 0.26; 'defined': 0.27; 'skip:" 20': 0.27; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'rest': 0.29; 'skip:p 30': 0.29; 'am,': 0.29; 'array': 0.29; 'character': 0.29; "doesn't": 0.30; 'code': 0.31; 'lines': 0.31; 'complete,': 0.31; 'object.': 0.31; 'pickle': 0.31; 'file': 0.32; 'supposed': 0.32; 'run': 0.32; 'text': 0.33; 'open': 0.33; 'says': 0.33; "can't": 0.35; 'editor': 0.35; 'objects': 0.35; 'really': 0.36; 'in.': 0.36; 'revert': 0.36; 'right?': 0.36; 'subject:?': 0.36; 'list': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'read': 0.60; 'hope': 0.61; 'lost': 0.61; "you're": 0.61; 'back': 0.62; 'save': 0.62; "you'll": 0.62; "you've": 0.63; 'email addr:gmail.com': 0.63; 'here': 0.66; 'reads': 0.68; '(ie': 0.84; '2.7.': 0.84; 'on?': 0.91; 'write()': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Thu, 13 Feb 2014 15:22:55 -0700 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Wait... WHAT? References: <6c76ef4e-8c7c-4199-b30d-c4d55c1061c8@googlegroups.com> <20140212161427.0a9843d5@bigbox.christie.dr> <20140212184432.1df9b491@bigbox.christie.dr> <20140212212953.458b810a@bigbox.christie.dr> <8778c4cc-334b-4254-aed7-0f33acbf1d8f@googlegroups.com> In-Reply-To: <8778c4cc-334b-4254-aed7-0f33acbf1d8f@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392330215 news.xs4all.nl 2882 [2001:888:2000:d::a6]:51008 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66264 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.