This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author anmolkejriwal
Recipients anmolkejriwal, paul.moore, steve.dower, tim.golden, zach.ware
Date 2019-11-28.07:17:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574925435.14.0.207210290632.issue38935@roundup.psfhosted.org>
In-reply-to
Content
The file modes a+, r+, w+ should read and write both. But a+ and w+ modes are not reading anything from the file. The RUN for the program is successful, but there is no output from the program.
Below is a simple program:

file=open("abcd.txt","w+")
l=["This is python.\nThis is an easy language.\nAnyone can learn this easily"]
file.writelines(l)
file.close()
file=open("abcd.txt","a+")   #Replacing with w+ also doesn't read.
file.write("123")      
t1=file.read()               #This read() does not work.
print(t1)                    #Does not print anything here.
file.close()

In r+ mode, it should write in the file without truncation and read it too. Instead, it is removing from the file, the equal number of characters I am trying to write in the file.
Below is the program:

file=open("abcd.txt","w+")
l=["This is python.\nThis is an easy language.\nAnyone can learn this easily"]
file.writelines(l)
file.close()
file=open("abcd.txt","r+")
file.write("123")
t1=file.read()
print(t1)

Output for this is:

s is python.
This is an easy language.
Anyone can learn this easily
History
Date User Action Args
2019-11-28 07:17:15anmolkejriwalsetrecipients: + anmolkejriwal, paul.moore, tim.golden, zach.ware, steve.dower
2019-11-28 07:17:15anmolkejriwalsetmessageid: <1574925435.14.0.207210290632.issue38935@roundup.psfhosted.org>
2019-11-28 07:17:15anmolkejriwallinkissue38935 messages
2019-11-28 07:17:14anmolkejriwalcreate