ı想要编写该命令,但它无法正常工作
for k in range 900 :
l=len(str(a[k]) **a[ ] is a string which gives random float numbers**
f.write("\n*l") **ı need to write space as the number of string length**
答案 0 :(得分:1)
乘法需要 on 字符串,而不是它。
f.write("\n" * l)
答案 1 :(得分:0)
我假设您正确地获得了长度,问题是写入文件。
您需要做的就是先保存到字符串并将该字符串写入文件。
temp = ''
for k in range 900 :
l=len(str(a[k]) **a[ ] is a string which gives random float numbers**
temp = temp + str(l) + "\n" # store all your values to temp string
f.write(temp) # then write than temp string into file