Doubt with files

Joaquin Alzola Joaquin.Alzola at lebara.com
Tue Feb 14 12:31:16 EST 2017


>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?

I do not know exactly what encoding rtf or the txt file has but you can use:

with open(dirFichero,'r',encoding='utf-8') as reader:
This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.



More information about the Python-list mailing list