def Readfile(file_path, remove_linebreaks=0, ignore_error=0):
data = []
if file_path == '-':
try:
data = sys.stdin.readlines()
except:
if not ignore_error:
Error(_('You must feed me with data on STDIN!'))
else:
try:
f = open(file_path)
data = f.readlines()
f.close()
except:
if not ignore_error:
Error(_("Cannot read file:") + ' ' + file_path)
if remove_linebreaks:
data = map(lambda x:re.sub('[\n\r]+$', '', x), data)
Message(_("File read (%d lines): %s") % (len(data), file_path), 2)
return data
评论列表
文章目录