writelines(list)
list : Input data as list . 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
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()
Author
🎥 Join me live on YouTubePassionate 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.