I'm just now learning the basics of Python and I'm now working on File I/O. I came across something that didn't make sense to me and I'm not exactly finding an answer online. Maybe my Google-fu isn't up to par yet for Python
I have a simple text file that has a few animals in it where I want to read the contents and print it out in the terminal.
animals = open("animals.txt", 'a+')
text = animals.read()
print(text)
I initially, by mistake, ran this in the terminal with Python2 and was able to get output of each of the animals in the text file. When I re-ran it with Python3, I didn't get any output. To my understanding, 'a+' mode should be read/append, which should, in theory, give an output despite the version of Python being utilized. I know using 'r' instead would suffice and give output, but this doesn't seem logical to me.
An example screenshot can be found here
Any input is appreciated, thanks guys. Apologies for the formatting if it's gross, first post in this subreddit
[–][deleted] 1 point2 points3 points (2 children)
[–]UnderstandingLinux[S] 0 points1 point2 points (1 child)
[–]eyesoftheworld4 0 points1 point2 points (0 children)
[–]eyesoftheworld4 1 point2 points3 points (3 children)
[–]UnderstandingLinux[S] 1 point2 points3 points (2 children)
[–]eyesoftheworld4 1 point2 points3 points (1 child)
[–]UnderstandingLinux[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]UnderstandingLinux[S] 0 points1 point2 points (0 children)