Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python writelines

f = open("demofile3.txt", "a")
f.writelines(["See you soon!", "Over and out."])
f.close()
Comment

writelines()

# readlines and writlines simple program
def finds() :
    f=open('file.txt')
    s=open('destination.txt','w')
    p=f.readlines()
    o=[]
    for i in p:
        if 'S' in i.upper():
            o.append(i)
    s.writelines(o)
    f.close()
    s.flush()
    s.close()
finds()

'''file.txt'''
''The life that I have
Is all that I have
And the life that I have
Is mine
The love that I have
Of the life that I have
Is mine and mine and mine.
A sleep I shall have
A rest I shall have
Yet death will be but a pause
For the peace of my years
In the long green grass
Will be mine and mine and mine.''
..............................................................................
#output:
'''destination.txt'''
..Is all that I have
Is mine
Is mine and mine and mine.
A sleep I shall have
A rest I shall have
Yet death will be but a pause
For the peace of my years
In the long green grass
Comment

write()and writelines() methods in python

Enter the name of the employee: Aditya
Enter the name of the employee: Aditi
Enter the name of the employee: Anil
Comment

PREVIOUS NEXT
Code Example
Python :: create and populate dictionary python 
Python :: set http response content type django 
Python :: instabot python 
Python :: merge two dictionaries in a single expression 
Python :: create new list in for loop python 
Python :: sort a series pandas 
Python :: django group by 
Python :: The Python path in your debug configuration is invalid. 
Python :: django createmany 
Python :: python opencv draw rectangle with mouse 
Python :: python print color 
Python :: randomforestregressor in sklearn 
Python :: how to delete role discord py rewrite 
Python :: python mahalanobis distance 
Python :: pandas backfill 
Python :: pandas replace row values based on condition 
Python :: list directory in python 
Python :: python tuple to list 
Python :: how to save the model in python 
Python :: how to convert cost to float in python 
Python :: rotate 90 degrees clockwise counter python 
Python :: python create sqlite db in memory 
Python :: pickle.dump python 
Python :: discord.py fetch channel 
Python :: pandas strip whitespace 
Python :: How to remove all characters after character in python? 
Python :: django drop all tables 
Python :: python library to make qr codes 
Python :: flask api abort 
Python :: python package version 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =