1

次のようなファイルを作成したい:

X 値:

1
2
3
4
5
.
.
.
999

そのために私はそのコマンドを書きましたが;

のようなエラー: argument 1 must be string or read-only character buffer, not float,,

from numpy import *

c = open("text.txt","w")
count = 0
while (count < 100):
   print  count
   count = count + 0.1
   c.write (count)
   c.close
4

3 に答える 3

0

また、while ループの反復ごとにファイルを閉じているため、最初の行が書き込まれてクラッシュします。

すべてが書き込まれた後にのみファイルが閉じられるように、最後の行のインデントを解除します。

while (count < 100):
    print  count
    count = count + 0.1
    c.write(str(count))
c.close()
于 2013-07-15T11:51:27.093 に答える