I know there are several post that have asked this question and I have tried some of the solutions but I still keep getting the error message. Both of the following solutions produce the same error message. What am I doing wrong?
Here is one solution I tried:
def main():
#Open a file named numbers.txt
numbers_file = open('numbers.txt','r')
#read the numbers on the file
file_contents = numbers_file.read()
#Close the the numbers file
numbers_file.close()
#Print the data that was inside the file
print(numbers_file)
#Call the main function
main()
Here is another solution I tried:
with open(r"numbers.txt",'r') as numbers_file:
#read the numbers on the file
file_contents = numbers_file.read()
#Close the the numbers file
numbers_file.close()
#Print the data that was inside the file
print(numbers_file)
The error message I get when I run either of the programs is:
<_io.TextIOWrapper name='numbers.txt' mode='r' encoding='cp1252'>
Thanks for the help. I realized what I was doing wrong. Here is what I got:
def main():
#Open a file named numbers.txt
numbers_file = open('numbers.txt','r')
#read the numbers on the file
file_contents = numbers_file.read()
#Close the the numbers file
numbers_file.close()
#Print the data that was inside the file
print(file_contents)
#Call the main function
main()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With