Krcevina
Krcevina

Reputation: 141

How to deal with the following symbol: ¶

I'm kinda new to Python. I need to read some text from one file (A), compare it with the text from another file (B), change a part of the earlier mentioned file and write it to the third one (C). Problem is A and B files files have unusual notation that involves this symbol "¶".

So, I managed to bypass it (ignore it) by reading (or writing) in the following way:

input = codecs.open('bla.txt', 'r', 'ascii', 'ignore');

But it's not good. I NEED to read it in precise way and compare it and write successfully.

So, content of my B file is: "Sugar=[Sugar@Butter¶Cherry]" but when I read it, my variable has the value Sugar=[Sugar@Butter¶Cherry] You can see, there is additional "Â"

Then my A file contains a lot of text which needs to be copied to the C file, except the certain part that follows after the above mentioned text in in B. That part needs to be changed and then written, BUT they are not the same, my program never enters the IF condition in which I am comparing the "Sugar=[Sugar@Butter¶Cherry]" form A and "Sugar=[Sugar@Butter¶Cherry]" from B.

Is there a way I can read the text so that this symbol "¶" appears as it is?

Upvotes: 0

Views: 159

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799120

Yes.

Use the correct encoding.

input = codecs.open('bla.txt', 'r', 'UTF-8', 'ignore')

Upvotes: 1

Related Questions