writelines()

writelines(list)
list : Input data as list .

Using 'w' mode

Details of different mode of file opening is shown here.
fob=open('data5.txt','w')
my_list=['Alex','Ronald','John']
fob.writelines(my_list)
fob.close()
# read data after writing 
fob=open('data5.txt','r')
print(fob.read()) # AlexRonaldJohn

Using 'a' mode

We used the same file as written above. As the mode of file open is 'a' , the data will be added at the end of the file.
fob=open('data5.txt','a')
my_list=['One','Two','Three']
fob.writelines(my_list)
fob.close()

fob=open('data5.txt','r')
print(fob.read()) # AlexRonaldJohnOneTwoThree
By using tell() method we can get the file object position. Here is the code to understand file position after writelines()
fob=open('data5.txt','w')
my_list=['Alex','Ronald','John']
fob.writelines(my_list)
print(fob.tell()) # 14 
fob.close() 
# read data after writing 
fob=open('data5.txt','r')
print(fob.tell()) # 0
print(fob.read()) # AlexRonaldJohn
fob=open('data5.txt','a')
my_list=['One','Two','Three']
fob.writelines(my_list)
print(fob.tell()) # 25
fob.close()

fob=open('data5.txt','r')
print(fob.tell()) # 0 
print(fob.read()) # AlexRonaldJohnOneTwoThree
writable()

File Append File Write
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer