-1

I wrote a code that should take a file written in English and print it but instead it returned some strange things. I posted the code and an image of the output. What should i do in order to solve the problem?

f = open("Introduction-first-part.docx")
print(f.read())

output

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Joker329
  • 1
  • 1
  • 3
    That is happening because the file is in `docx` format. Try converting it to plain text and reading it instead. – C_Z_ Jan 21 '20 at 19:28

1 Answers1

1

Try reading in a .txt file instead. .docx is a microsoft word format which does not store text in plaintext which means when you read it you will not get 'english'. It stores things like fonts, spacing, size, and a lot of other information aside form just the contents of the file.

Copy your text out into a different format if you want to read it with python is probably the easiest way.

cmxu
  • 954
  • 5
  • 13