def write_as(self, text, the_encoding=""):
try:
if the_encoding == "": #if the developer did not include the encoding type, raise an exception
raise RuntimeError("The text encoding was not specified as an argument to the write_as() method (Naked.toolshed.file.py:write_as).")
import codecs
with codecs.open(self.filepath, encoding=the_encoding, mode='w') as f:
f.write(text)
except Exception as e:
if DEBUG_FLAG:
sys.stderr.write("Naked Framework Error: unable to write file with the specified encoding using the write_as() method (Naked.toolshed.file.py).")
raise e
#------------------------------------------------------------------------------
# [ write_bin method ]
# binary data file writer
# Tests: test_IO.py :: test_file_bin_readwrite
#------------------------------------------------------------------------------
评论列表
文章目录