bradworks
bradworks

Reputation: 89

How to open text documents in python

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?

Upvotes: 1

Views: 489

Answers (1)

Nate.Olson
Nate.Olson

Reputation: 153

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).

Upvotes: 1

Related Questions