Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
2+1 =