1

我想写那个命令,但它不工作

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**
4

2 回答 2

1

The multiplication needs to be on the string, not in it.

f.write("\n" * l)
于 2013-07-18T06:11:18.680 回答
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
于 2013-07-18T06:29:25.293 回答