0

I have a text file like below

    # 1.txt
    who is the\u00a0winners\u00a0where\u00a0season result\u00a0is 7th

If I read a file and print it, it shows

    >>> s = open("1.txt").read()
    >>> print(s)
    who is the\u00a0winners\u00a0where\u00a0season result\u00a0is 7th

However, If I do like below with the same string,

    >> s = "who is the\u00a0winners\u00a0where\u00a0season result\u00a0is 7th"
    >> print(s)
    who is the winners where season result is 7th


I want to read a text file like "1.txt" and print it like the below one. I can not find how to do it. Please help me. Thanks.

3
  • \u.... in string literals are being interpreted, read from text files they're not. Commented Apr 9, 2018 at 8:11
  • Seems to have been discussed already before. Please have a look at : stackoverflow.com/questions/2594810/… Commented Apr 9, 2018 at 8:18
  • @deceze, Thanks for your comment. Is there a way to handle \u... in text file? Commented Apr 9, 2018 at 8:32

1 Answer 1

0

\u00a0 is a non break space and is one character.

In your first example your are reading \u00a0 as 6 chars.

If you want to read a file with \u00a0s and interpret them as spaces, you would have to parse the file yourself and create spaces for each \u00a0.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. However, I have several more unicodes. \u20132, \u20136, \u00e4 etc. Should I parse every \u things to read it? Thanks.
If you look at the question in the answer of @Kenstars, one answer to that question is stackoverflow.com/a/2594942/4572356 . It is maybe the easiest way to do what you want to accomplish. Essentially using .replace on the string to replace a \u... with what it's definition is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.