test_csv.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:ndk-python 作者: gittor 项目源码 文件源码
def test_int_write(self):
        import array
        contents = [(20-i) for i in range(20)]
        a = array.array('i', contents)

        fd, name = tempfile.mkstemp()
        fileobj = os.fdopen(fd, "w+b")
        try:
            writer = csv.writer(fileobj, dialect="excel")
            writer.writerow(a)
            expected = ",".join([str(i) for i in a])+"\r\n"
            fileobj.seek(0)
            self.assertEqual(fileobj.read(), expected)
        finally:
            fileobj.close()
            os.unlink(name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号