0% found this document useful (0 votes)
4 views6 pages

Adobe Scan 02-Feb-2021

Uploaded by

chandanag023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Adobe Scan 02-Feb-2021

Uploaded by

chandanag023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

P sert

Eating

NAME: VEDA SAMHITHA DATE:1-2-2021

1608-19-737-034

PROGRAMS RELATED TO FILE:

CREATED FILE NAMED DEMOFILE AND WRITTEN sOME CONTENT AND DISPLAYED IT:

1 with open('demofile.txt, w') as f:

#first line of file

f.writecreating my first file\n')

#second line of file

f.write(This is first line\n')

#third line of file

f.write'l am from IT department\n')

with open('demofile.txt', '") as f:T

content= f.readlines()

for line in content:

print(line)

OUTPUT:

creating my first file

This is first line


I am from IT department

READ SOME LINE cONTENT FROM EARLIERLY CREATED FILE:

2 with open("demofile.txt", "") asf:

data = f.readlines()

for line in data:

words = Iine.split()

print (words)

OUTPUT:

T,'am', 'from', 'IT', 'department']

DELETING FILE CONTENT HAVING 2 CASES:

1 IF FILE EXISTED WHICH WONNA DELETE:


Find
ac Replace
Picture Paint Date and Insert
time object
Select all
drawing
aragraph Insert Editing

DELETING FILE CONTENT HAVING 2 CASES:


1 IF FILE EXISTED WHICH WONNA DELETE:

3 import os

with open ('create.txt','w') as p:

p.write('my first line of file\n')

p.write(just now created\n')

if os.path.exists("create.txt"):

Os.remove("create.txt")
else:

print("the file does not exist"

OUTPUT:

RESTART:
C:/Users/91939/AppData/Local/Programs/Python/Python39/file 3.py ==

ALL THE CONTENT GET DELETED

2 IF FILE WHICH WE ARE


DELETING DOES NOT EXIST:

4 import os

with open
('create.txt','w') as p:
p.write'my first line of file\n')
P.write(just now created\n')

O
if os.path.exists("crfile.txt"):

os.remove("crfile.txt")

else
print("the file does not exist")

OUTPUT

the file does not exist

PROGRAM FOR COPYING CREATE NAMED FILE CONTENT TO OUT.TXT FILE:

5 with open('create.txt') as f:

with open('out.txt,w') as y:

for line in f:

y.write(line)

with open('out.txt',r) as y:
content=y.readlines()
for line in content:
print(line)

OUTPUT

my first line of file

just now created

PYTHON REGULAR EXPRESSIONS:

SEARCHING A WORD IN GIVEN STATEMENT

1 import re

if re.search("RED", "RED IS THE NEW BLUE"):


print("RED found")

else

print("NO RED IN GIVEN STATEMENT")

OUTPUT:

RED found
FINDING ALL THE WORDS NEEDED IN STATEMENT

2 import re

result= re.findall(r'one', 'be one to do one')

print(result)
OUTPUT:

l'one', 'one]

You might also like