import os
def WriteFile(Value):
fo = open(“foo.txt”, “w”)
fo.write(Value)
fo.close()
def AppendFile(Value):
fo = open(“foo.txt”, “a”)
fo.write(Value)
fo.close()
def ReadFile():
try:
fo = open(“foo.txt”, “r”)
ss = fo.read()
fo.close()
except RuntimeError:
ss = “File does not exists First run Write Option”
except IOError as ErrorMsg:
ss = ErrorMsg
except:
ss = “Other Error”
return ss
def ReadFileChars(count):
try:
fo = open(“foo.txt”, “r+”)
directory = os.getcwd()
file_size = os.path.getsize(directory + ‘\\foo.txt’)
file_size = int(file_size)
count = int(count)
if (count > file_size):
raise Exception(“file size”)
ss = fo.read(count)
fo.close()
except Exception as e:
ss = e
return ss
def ReadFileCharsPos(count, pos):
fo = open(“foo.txt”, “r+”)
position = fo.seek(int(pos), 0)
ss = fo.read(int(count))
fo.close()
return ss