本文整理汇总了Python中File.File.read方法的典型用法代码示例。如果您正苦于以下问题:Python File.read方法的具体用法?Python File.read怎么用?Python File.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File.File
的用法示例。
在下文中一共展示了File.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import read [as 别名]
def read(self, ifname):
"""Returns new Png instance containing contents of png file on disk."""
imagefile = File(ifname)
chunks = imagefile.read()
if len(chunks) != 3:
print 'png file must consist exactly of',
print 'IHDR, IDAT, and IEND chunks'
return True
for c in chunks:
if self._parse_chunk(c):
return True
return False
示例2: main
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import read [as 别名]
def main():
f = "tsp-medium.tsp"
j = File.read(f) # to generate data, use the R_File.read access
t = TwoOpt(j) # returns an object ready to sort
pylab.show()
pylab.waitforbuttonpress()
t.sort() # one round of sorting
# finally, once it's finished, just wait for button press
pylab.waitforbuttonpress()
pylab.close()
示例3: _send_file
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import read [as 别名]
def _send_file(self, file_path):
fields = [("apikey", self._key)]
target_file = File(file_path)
content = target_file.read()
del target_file
files = [("file", os.path.basename(file_path), content)]
json_str = postfile.post_multipart(self._host, self._url_scan, fields, files)
if json_str == '':
return False
data = json.loads(json_str)
if data['response_code'] == 1:
return True
else:
return False