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
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







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 Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer