0

Here is my code:

with open(path) as file:
    lines = file.readlines()
    print lines[0:5]

However I get many extra characters, for example:

['cat2\xc2\xa0\xc2\xa0 2\xc2\xa0 0', 'cat1\xc2\xa00.5\xc2\xa0 0', 'cat2\xc2\xa0\xc2\xa0 1\xc2\xa0 0', 'cat1\xc2\xa0\xc2\xa0 0\xc2\xa0 0', 'cat2\xc2\xa0\xc2\xa0 0\xc2\xa0 3']

Why do I get them?

The original text file was this:

cat2   2  0
cat1 0.5  0
cat2   1  0
cat1   0  0
cat2   0  3
Danil Speransky
  • 29,891
  • 5
  • 68
  • 79

1 Answers1

2

\xc2\xa0 is a non-breaking space. Replace it with regular spaces in the file.

This sequence appears in many encodings including UTF-8.

See more on Wikipedia

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79