tensorflow是可以直接读写hdfs的,主要有:
tf.io.gfile.GFile(
name, mode='r'
) //读写文件
flush() //写完最好用以下,不然有些还在buff中
close() //关闭数据流
readline //读取一行
readlines //读取所有行返回list,这个有个坑,在文件很大时超慢
优先使用readline,需要判断啥时候结束
fsamp = tf.io.gfile.GFile('hdfs://query', mode='r')
while True:
line = fsamp.readline()
if not line: //读完
break
print(line)