1

I have written a text document in notepad. The encoding is UTF-8. I have saved the text document as bradley. I want to read the document using python 3.4 here is my code:

doc=open("bradley.txt","r",encoding="UTF-8")
doc.readlines()
doc.close()

I get the error.TypeError: an integer is required (got type str) I removed the "r" so that my code isdoc=open("bradley.txt",encoding="UTF-8") when i run it...The IDLE gives me nothing. what i was expecting is that i get the contents of the file. How can i achieve that?

bradworks
  • 89
  • 10
  • 1
    As I remember notepad adds [BOM](https://en.wikipedia.org/wiki/Byte_order_mark) to the UTF-8 files. Does Python `readlines()` have a parameter to skip them when found? – Gábor Bakos Nov 25 '15 at 07:54
  • 1
    The "r" is for read-only, so it shouldn't have any effect here. You should put here the actual code and the error, this code doesn't require any integer. – Cătălin Matei Nov 25 '15 at 12:06
  • the error and the code are above – bradworks Nov 25 '15 at 15:27
  • Your code for reading the file seems correct, so the problem must be in the file and/or notepad. – DainDwarf Nov 25 '15 at 16:03
  • Possible duplicate of [Reading Unicode file data with BOM chars in Python](http://stackoverflow.com/questions/13590749/reading-unicode-file-data-with-bom-chars-in-python) – Gábor Bakos Nov 28 '15 at 18:49

1 Answers1

1

You could rename the ending to .py and import it, like so:

from bradley import *

I have a platformer which scrolls the screen, and I have a function in a separate document called player.py. I can call that function from withing the main program by using from player import Player at the beggining of the code (where Player is the function).

Nate.Olson
  • 133
  • 1
  • 12