本文整理汇总了Python中Matrix.matrixFromCSVFile方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.matrixFromCSVFile方法的具体用法?Python Matrix.matrixFromCSVFile怎么用?Python Matrix.matrixFromCSVFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.matrixFromCSVFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReadCSV
# 需要导入模块: import Matrix [as 别名]
# 或者: from Matrix import matrixFromCSVFile [as 别名]
def testReadCSV(self):
'''Tests if a matrix can be properly initialised from a csv file'''
#Test can read csv files produce by the class itself
string = self.matrix.csvRepresentation()
file = open('temp', 'w')
file.write(string)
file.close()
matrix = Matrix.matrixFromCSVFile('temp')
self.assertEqual(matrix, self.matrix)
os.remove('temp')
#Test initialisation for a csv file not in the same format
#as the one created by the Matrix class
file = open('temp', 'w')
file.write(testCSVString)
file.close()
matrix = Matrix.matrixFromCSVFile('temp')
self.assertEqual(matrix, self.matrix)
#Test it works when told not to read header
file = open('temp', 'w')
file.write(testCSVString2)
file.close()
matrix = Matrix.matrixFromCSVFile(filename='temp', readHeaders=False)
matrix.setColumnHeaders(["Header1", "Header2"])
self.assertEqual(matrix, self.matrix)
#Clean up
os.remove('temp')