本文整理汇总了Python中io.FileIO.readall方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.readall方法的具体用法?Python FileIO.readall怎么用?Python FileIO.readall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.FileIO
的用法示例。
在下文中一共展示了FileIO.readall方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_zipdata
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import readall [as 别名]
def get_zipdata(self):
cache_file_name = self.cache_filename
stream = FileIO(cache_file_name, mode='w')
zipfile = ZipFile(stream, 'w')
self.write_zipfile(zipfile)
zipfile.close()
stream.close()
stream = FileIO(cache_file_name, mode='r')
zipdata = stream.readall()
stream.close()
remove(cache_file_name)
return zipdata
示例2: FileDataReader
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import readall [as 别名]
class FileDataReader(AbstractDataReader):
""" A reader that can read data from a file
"""
def __init__(self, filename):
"""
:param filename: The file to read
:type filename: str
:raise spinnman.exceptions.SpinnmanIOException: If the file\
cannot found or opened for reading
"""
try:
self._fileio = FileIO(filename, "r")
except IOError as e:
raise SpinnmanIOException(str(e))
def read(self, n_bytes):
""" See :py:meth:`spinnman.data.abstract_data_reader.AbstractDataReader.read`
"""
return bytearray(self._fileio.read(n_bytes))
def readinto(self, data):
""" See :py:meth:`spinnman.data.abstract_data_reader.AbstractDataReader.readinto`
"""
return self._fileio.readinto(data)
def readall(self):
""" See :py:meth:`spinnman.data.abstract_data_reader.AbstractDataReader.readall`
"""
return self._fileio.readall()
def close(self):
""" Closes the file
:return: Nothing is returned:
:rtype: None
:raise spinnman.exceptions.SpinnmanIOException: If the file\
cannot be closed
"""
try:
self._fileio.close()
except IOError as e:
raise SpinnmanIOException(str(e))
示例3: load_from_file
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import readall [as 别名]
def load_from_file(filename):
f = FileIO(filename, 'rb')
data = f.readall()
return ByteArray(data)
示例4: len
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import readall [as 别名]
"""
import sys
import io
from io import FileIO
inputFileName = sys.argv[1]
outputFileName = sys.argv[2]
nInLine = 10
if len(sys.argv) >= 4:
nInLine = int(sys.argv[4])
inputStream = FileIO(inputFileName, "r")
outputFile = open(outputFileName, "w")
inputData = inputStream.readall()
inputStream.close()
outputStr = ""
n = 0
for x in inputData:
outputStr += str(ord(x)).rjust(3) + ", "
n += 1
if n >= nInLine:
outputStr += "\n"
n = 0
outputFile.write(outputStr)
outputFile.close()