beginner's python help

Benjamin Kaplan benjamin.kaplan at case.edu
Sun Sep 6 09:11:53 EDT 2009


On Sun, Sep 6, 2009 at 4:28 AM, Maggie<la.foma at gmail.com> wrote:
> On Sep 6, 4:19 am, Chris Rebert <c... at rebertia.com> wrote:
>> On Sun, Sep 6, 2009 at 1:10 AM, Maggie<la.f... at gmail.com> wrote:
>> > On Sep 6, 3:58 am, Chris Rebert <c... at rebertia.com> wrote:
>> >> On Sun, Sep 6, 2009 at 12:54 AM, hrishy<hris... at yahoo.co.uk> wrote:
>> >> > Hi
>>
>> >> > sum = 0
>> >> >  for item in readData:
>> >> >     try:
>> >> >         sum += int(item)
>> >> >     except ValueError:
>> >> >         print "Oops!  That was no valid number. Instead it was:", item
>>
>> >> > So you mean to say this would ignore the bad data and continue processing ?
>>
>> >> Yes. A new "try" happens every loop iteration since the "try" is
>> >> within the loop body.
>>
>> >> Cheers,
>> >> Chris
>> >> --http://blog.rebertia.com
>>
>> > Wow, thanks for your suggestions, Chris. Exceptions are really
>> > useful..
>> > when i try running the script now I get a whole bunch of errors like
>> > this one --
>>
>> > [jodorowskys-macbook-pro:~/desktop/formisano_replication] Jodorowsky%
>> > python test1.py
>> > That was not a valid number. Instead it was: {\rtf1\ansi
>> > \ansicpg1252\cocoartf949\cocoasubrtf540
>>
>> > That was not a valid number. Instead it was: {\fonttbl\f0\fswiss
>> > \fcharset0 Helvetica;}
>>
>> > That was not a valid number. Instead it was: {\colortbl;
>> > \red255\green255\blue255;}
>>
>> > That was not a valid number. Instead it was:
>> > \margl1440\margr1440\vieww9000\viewh8400\viewkind0
>>
>> > That was not a valid number. Instead it was: \pard
>> > \tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql
>> > \qnatural\pardirnatural
>>
>> > That was not a valid number. Instead it was: \f0\fs24 \cf0 32 123 231
>> > 432 12}
>>
>> > -------------
>>
>> > why is it reading in all of the above? and how do I fix it and avoid
>> > it in the future?
>>
>> Your file appears to be saved in Rich Text Format (RTF) rather than
>> plain text (.TXT), hence Python is seeing all the formatting
>> gibberish.
>> Re-save it in the correct file format and try again.
>>
>> Cheers,
>> Chris
>> --http://blog.rebertia.com
>
> the problem is - it is saved as a .txt and not in .rtf.. which is why
> this error seems so bizarre..!

The first thing you should understand about files- those extensions
are absolutely meaningless. All they do is tell your OS which program
to use to open it. When it boils down to it, every file is just a
collection of 1s and 0s. Just because your file says ".txt" does not
mean that it is a plain text file. Open up TextEdit and go to Format
-> Make Plain Text and then save it again.
]



More information about the Python-list mailing list