def append(self, text):
try:
from Naked.toolshed.system import file_exists
if not file_exists(self.filepath): #confirm that file exists, if not raise IOError (assuming that developer expected existing file if using append)
raise IOError("The file specified for the text append does not exist (Naked.toolshed.file.py:append).")
with open(self.filepath, 'a') as appender:
appender.write(text)
except UnicodeEncodeError as ue:
self.append_utf8(text) #try writing as utf-8
except Exception as e:
if DEBUG_FLAG:
sys.stderr.write("Naked Framework Error: Unable to append text to the file with the append() method (Naked.toolshed.file.py).")
raise e
#------------------------------------------------------------------------------
# [ append_utf8 method ]
# Text writer that appends text to existing file with utf-8 encoding
# Tests: test_IO.py :: test_file_utf8_readwrite_append
#------------------------------------------------------------------------------
评论列表
文章目录