请问DolphinDB database中有没有函数可以获取csv文件的行数?

为了获取CSV文件的行数,我写了下列自定义函数,有没有效率更高的写法?

def getLines(fileName){
fin = file(fileName)
sz=0;
y=array(STRING,1024)
do{
lines=fin.readLines!(y,0,1024)
sz+=lines
} while(lines==1024)
fin.close()
return sz;
}
请先 登录 后评论

1 个回答

Jason Tang - 时序数据库技术支持

参考https://www.dolphindb.cn/cn/h...,写函数如下:

def lineCount(fileName){
 h = file(fileName)
 bufSize = 102400
 buf = array(CHAR, bufSize)
 lines = 0
 do {
   numByte = h.read!(buf,0,bufSize)
   lines += sum(subarray(buf, 0 : numByte) == '\n')
 }while(numByte == bufSize)
 return lines
}
请先 登录 后评论