本文整理汇总了Python中bz2.BZ2File.writelines方法的典型用法代码示例。如果您正苦于以下问题:Python BZ2File.writelines方法的具体用法?Python BZ2File.writelines怎么用?Python BZ2File.writelines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bz2.BZ2File
的用法示例。
在下文中一共展示了BZ2File.writelines方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWriteLines
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import writelines [as 别名]
def testWriteLines(self):
# "Test BZ2File.writelines()"
with BZ2File(self.filename, "w") as bz2f:
self.assertRaises(TypeError, bz2f.writelines)
sio = StringIO(self.TEXT)
bz2f.writelines(sio.readlines())
# patch #1535500
self.assertRaises(ValueError, bz2f.writelines, ["a"])
with open(self.filename, 'rb') as f:
self.assertEqual(self.decompress(f.read()), self.TEXT)
示例2: testWriteMethodsOnReadOnlyFile
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import writelines [as 别名]
def testWriteMethodsOnReadOnlyFile(self):
with BZ2File(self.filename, "w") as bz2f:
bz2f.write("abc")
with BZ2File(self.filename, "r") as bz2f:
self.assertRaises(IOError, bz2f.write, "a")
self.assertRaises(IOError, bz2f.writelines, ["a"])
示例3: testWriteLines
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import writelines [as 别名]
def testWriteLines(self):
# "Test BZ2File.writelines()"
bz2f = BZ2File(self.filename, "w")
self.assertRaises(TypeError, bz2f.writelines)
sio = StringIO(self.TEXT)
bz2f.writelines(sio.readlines())
bz2f.close()
# patch #1535500
self.assertRaises(ValueError, bz2f.writelines, ["a"])
f = open(self.filename, 'rb')
self.assertEqual(self.decompress(f.read()), self.TEXT)
f.close()
示例4: testWriteMethodsOnReadOnlyFile
# 需要导入模块: from bz2 import BZ2File [as 别名]
# 或者: from bz2.BZ2File import writelines [as 别名]
def testWriteMethodsOnReadOnlyFile(self):
bz2f = BZ2File(self.filename, "w")
bz2f.write("abc")
bz2f.close()
bz2f = BZ2File(self.filename, "r")
self.assertRaises(IOError, bz2f.write, "a")
self.assertRaises(IOError, bz2f.writelines, ["a"])