Question: Please write a program using the module posted below. Please only use Python 3. Thank you. #Floren Lebaron #This is the Module for my open()
Please write a program using the module posted below. Please only use Python 3. Thank you.
#Floren Lebaron
#This is the Module for my open() project.
#The program needs to use a SheBang, like, #!/usr/bin/env python3
#The path needs to be defined for the spesific computer this code is running on at the time.
import os
#This part reads the file in the path decided. I removed my computer path for submission.
def readFile(filePath):
#This opens a file using the Open() function.
g = os.open(filePath,"r")
#This checks to see if the file is in open mode.
if g.mode == "r":
#This is the read lines function for reading files.
lines = g.readlines()
for line in lines:
print(line)
#If you wan't to write to a file, choose the path.
def writeToFile(filePath):
#This opens a file in chosen path.
#A new file will be created if the chosen file does not exist.
g = os.open(filePath,"w+")
#writes sample numbers to file
for i in range(5):
g.write("WRITTING! " % (i+1))
#closes file when write is done
g.close()
#appends data to file
def appendToFile(filePath):
#opens file to append data. If the file with that name does not exist, it creates a new one.
g = os.open(filePath,"a+")
#Sample data to load
for i in range(6,11):
g.write("appending data " % (i+1))
#This closes the file when complete
g.close()
Program Example,
#Using the OpenModule.py Module
import OpenModule
OpenModule.readFile("path of File")
OpenModule.writeToFile("path of file")
OpenMudule.appendToFile("path of file")
Note: Please test the program and module in Repl.it.
Please only use Python 3
Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
