Doubt with files

boB Stepp robertvstepp at gmail.com
Tue Feb 14 12:38:28 EST 2017


On Tue, Feb 14, 2017 at 11:13 AM, José Manuel Suárez Sierra
<josemsuarezsierra at gmail.com> wrote:
> hello,
> im trying to read a rtf or txt file with this python script:
>
> with open(dirFichero,'r') as reader:
>     for line in reader:
>         print line
>
> the problem is that shown is :
>
> {\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf810
>
> {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
>
> {\colortbl;\red255\green255\blue255;}
>
> {\*\expandedcolortbl;;}
>
> \paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
>
> \pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
>
>
>
> \f0\fs24 \cf0 1l2m,1svo,1lme}
>
>
> INSTEAD of:
> 1l2m,1svo,1lme
>
> How could I fix it?

Your program seems to be faithfully printing out the contents of your
rtf file as a txt file, showing all of the rtf formatting code.  If
you want a different result, I suggest you search online for something
like:  python read write rtf


-- 
boB



More information about the Python-list mailing list