def safe_write_bin(self, file_data):
try:
import os.path
if not os.path.exists(self.filepath):
with open(self.filepath, 'wb') as writer:
writer.write(file_data)
return True
else:
return False
except Exception as e:
if DEBUG_FLAG:
sys.stderr.write("Naked Framework Error: Unable to write to requested file with the safe_write_bin() method (Naked.toolshed.file.py).")
raise e
#------------------------------------------------------------------------------
# [ write_utf8 method ]
# Text file writer with explicit UTF-8 text encoding
# uses filepath from class constructor
# requires text to passed as a method parameter
# Tests: test_IO.py :: test_file_utf8_readwrite, test_file_utf8_readwrite_raises_unicodeerror
#------------------------------------------------------------------------------
评论列表
文章目录