def read_as(self, the_encoding):
try:
if the_encoding == "":
raise RuntimeError("The text file encoding was not specified as an argument to the read_as method (Naked.toolshed.file.py:read_as).")
import codecs
with codecs.open(self.filepath, encoding=the_encoding, mode='r') as f:
data = f.read()
return data
except Exception as e:
if DEBUG_FLAG:
sys.stderr.write("Naked Framework Error: Unable to read the file with the developer specified text encoding with the read_as method (Naked.toolshed.file.py).")
raise e
#------------------------------------------------------------------------------
# [ readlines method ] (list of strings)
# Read text from file line by line, uses utf8 encoding by default
# returns list of utf8 encoded file lines as strings
# Tests: test_IO.py :: test_file_readlines, test_file_readlines_missing_file
#------------------------------------------------------------------------------
评论列表
文章目录