Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding: utf-8
- # #Experiment 1
- # In[30]:
- import os
- with open('std_records.txt','w') as file:
- file.write('Student Name,Roll Number,Student Marks\n')
- file.write('John,1001,98\n')
- file.write('Ben,1002,84\n')
- file.write('Tom,1003,91\n')
- file.write('Adam,1004,76\n')
- file.write('Tim,1005,89')
- print("Records Inserted Successfully")
- # In[31]:
- if os.path.exists('std_records.txt'):
- with open('std_records.txt','r') as file:
- print(file.read())
- else:
- print("Student Records Doesnt Exist")
- # In[32]:
- if os.path.exists('std_records.txt'):
- roll_number = input("Enter Student Roll Number:")
- with open('std_records.txt', 'r') as file:
- header = file.readline()
- found = False
- for line in file:
- if roll_number in line:
- print(f"Record Found:\n{header}{line.strip()}")
- found = True
- break
- if not found:
- print("Record not found.")
- else:
- print("Student Records Doesnt Exist")
- # In[33]:
- with open('C:\\Users\\Student\\Pictures\\sampleimg.jpg','rb') as img:
- imagedata = img.read()
- # In[34]:
- from PIL import Image
- import matplotlib.pyplot as plt
- with open('output_image.jpg','wb') as img:
- image = img.write(imagedata)
- image = Image.open('output_image.jpg')
- plt.imshow(image)
- plt.axis("off")
- plt.show()
- # In[35]:
- import zipfile
- with zipfile.ZipFile("student_zipped.zip",'w') as zipf:
- zipf.write('std_records.txt')
- zipf.write('student_details.bin')
- print("Files Zipped Successfully")
- # In[36]:
- with zipfile.ZipFile("student_zipped.zip",'r') as zipf:
- zipf.extractall("Student Details")
- print("Files Unzipped Successfully")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement