numpy.loadtxt读入的字符串总是bytes格式
-柚子皮-
优质创作者: 人工智能技术领域
领域专家: 数据科学与机器学习技术领域 2015-03-11 10:32:54 2.txt文件内容:
love byte you
file = open(r'C:\Users\pi\Desktop\2.txt')
d = loadtxt(file, dtype=str)
print(d[0])
["b'love'" "b'byte'" "b'you'"]
file = open(r'C:\Users\pi\Desktop\2.txt', 'rb')
d = loadtxt(file, dtype=str)
print(d)
["b'love'" "b'byte'" "b'you'"]
file = open(r'C:\Users\pi\Desktop\2.txt', 'r', encoding='utf-8')
d = loadtxt(file, dtype=str)
print(d)
["b'love'" "b'byte'" "b'you'"]
为什么输出就是不能为['love' 'byte' 'you'] ?!