Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- file = open('demo.txt','w')
- file.write("Hello World!")
- file.close()
- file = open('demo.txt','r')
- print(file.read())
- file.close()
- with open('demo.txt','a') as file:
- file.write("\nHave a good day")
- with open('demo.txt','r') as file:
- print(file.read())
- with open('demo.txt','r') as file:
- file.seek(6)
- print(file.tell())
- content = file.read()
- print(content)
- print(file.tell())
- import os
- file = open('demo.bin','wb')
- file.write(b"Hello World!")
- file.close()
- file = open('demo.bin','rb')
- print(file.read())
- file.close()
- with open('demo.bin','ab') as file:
- file.write(b"\nHave a good day")
- with open('demo.bin','rb') as file:
- print(file.read())
- with open('demo.bin','rb') as file:
- file.seek(6)
- print(file.tell())
- content = file.read()
- print(content)
- print(file.tell())
- import zipfile
- with zipfile.ZipFile("zipped_files.zip",'w') as zipf:
- zipf.write("demo.txt")
- zipf.write("demo.bin")
- print("Files Zipped Successfully")
- with zipfile.ZipFile("zipped_files.zip",'r') as zipf:
- zipf.extractall("unzipped_files")
- print("Files Unzipped Successfully")
- if os.path.exists('demo.txt'):
- os.remove('demo.txt')
- print("File Deleted")
- else:
- print("File doesn't exist")
- if os.path.exists('demo.bin'):
- os.remove('demo.bin')
- print("File Deleted")
- else:
- print("File doesn't exist")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement