我想写那个命令,但它不工作
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**
The multiplication needs to be on the string, not in it.
f.write("\n" * l)
我假设您正确获取长度,问题是写入文件。
您需要做的就是先保存到字符串并将该字符串写入文件。
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