B A
B A

Reputation: 69

Convert Unicode to ANSI or UTF8 in python

I am using Python 2.7.8 and I have a script which does parsing:

def parse():
    with open('myfile.txt') as f:
.
.
.
Print l

myfile.txt has a UNICODE coding. How can I add a code to this script so that it reads the myfile.txt as ANSI for example?

Upvotes: 0

Views: 3094

Answers (1)

B A
B A

Reputation: 69

using io solved my problem:

import io    
def parse()
    with io.open(path,'r',encoding='utf_16') as f:
.....

solved my problem.

Upvotes: 2

Related Questions