What would the syntax look like when decoding a file,when I try to open the file it shows this #<_io.TextIOWrapper name='DOB.txt' mode='r+' encoding='cp1252'>
Your resulting printout is actually your opened file (it's an object).
I suppose you're opening the file like this:
f = open("DOB.txt", "r+", encoding="cp1252")
Directly printing f
will result in your current printed string.
To actually retrieve the contents of your file, you need to call the read
method.
Example:
f = open("DOB.txt", "r+", encoding="cp1252")
content = f.read()
content
will become the contents of your file as a single string whereas newlines are being encoded by a newline character (depending on your OS either \r\n
(on Windows) or \n
on a UNIX-based OS)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.