Message357609
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 |
|
Date |
User |
Action |
Args |
2019-11-28 07:17:15 | anmolkejriwal | set | recipients:
+ anmolkejriwal, paul.moore, tim.golden, zach.ware, steve.dower |
2019-11-28 07:17:15 | anmolkejriwal | set | messageid: <1574925435.14.0.207210290632.issue38935@roundup.psfhosted.org> |
2019-11-28 07:17:15 | anmolkejriwal | link | issue38935 messages |
2019-11-28 07:17:14 | anmolkejriwal | create | |
|