appstore/generator/GeneralFunctions/InputOutput.py

34 lines
746 B
Python
Raw Normal View History

from os.path import isfile as DoesFileExist
2020-04-27 08:12:38 +02:00
from .DataStructureManipulations import ConvertToStandardPathFormat
def ReadTextFile(FilePath):
FilePath = ConvertToStandardPathFormat(FilePath)
if DoesFileExist(FilePath) is True:
File = open(FilePath)
ReadFile = File.read()
File.close()
return ReadFile
else:
return ''
def ReadlinesTextFile(FilePath):
String = ReadTextFile(FilePath)
return String.split('\n')
def WriteTextFiles(FilePath, Text):
if type(Text) != str:
Text = '\n'.join(Text)
File = open(FilePath, 'w')
File.write(Text)
File.close()
def WriteBinaryToFile(Filepath, Data):
File = open(Filepath, 'wb')
File.write(Data)
File.close()