因此,我编写了以下简单的Python脚本,该脚本从CSV接收数据并为3D打印机输出这些配置文件。一切工作正常,但当我在double for循环中将字符串添加在一起时,它将在32个字符后切断字符串。谁能解释为什么会这样以及如何预防呢?预先感谢!
import numpy as np
file = open('QualityData.csv')
data = np.genfromtxt(file, delimiter=",",dtype=str) #importing data
headers=data[[0,1],:]
data = np.delete(data,(0,1),0) #delete rows
titles=data[:,0]
data = np.delete(data, 0,1) #delete columns
r,c=np.shape(data)
profs = np.zeros((r,c))
profs = np.array(profs,dtype=str) #build data array for config file
for i in range(r): #fill data array
for j in range(c):
if i in (0,4,5,12,13):
profs[i,j]=titles[i]
else:
profs[i,j]=titles[i]+' = '+data[i,j]
print(profs[i,j])
for k in range(c): #create filename and save it
varient=str(data[11,k])
varient=varient.replace(' ','_')
filename = str(data[10,k]) + '_' + varient + '_' + str(data[8,k])+'.inst.cfg'
np.savetxt(filename, profs[:,k], newline='\n',fmt='%s')
将长度超过32个字符的字符串毫无问题地放入titles数组,但是在else语句中将它们加在一起时,它仅接受前32个字符。