beginner's python help

MRAB python at mrabarnett.plus.com
Sun Sep 6 15:38:23 CEST 2009


Chris Rebert wrote:
> On Sun, Sep 6, 2009 at 1: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
> 
> I assure you, it is not.
> 
You're saving it as Rich Text Format, but with a .txt extension. You
need to save it as plain text with a .txt extension.



More information about the Python-list mailing list