0

属性ジェネレーターを作成しようとしていて、値を保存する必要があります。私が抱えている唯一の問題は、文字列ではなく浮動小数点数を格納しているがまだ変更方法がわからないことです。

score = dtwo/done
print(int (score))
strength=score + initial

myFile = open( name + "'s Strength", 'wt')
myFile.write(strength)
myFile.close()

無知なので教えてください....

4

2 に答える 2

2

これを使って:

myFile.write(str(strength))

またはこれ:

myFile.write(repr(strength))

桁数を指定するには:

myFile.write('{0:.5f}'.format(strength))

str.formatここでの書式設定の詳細: http://docs.python.org/2/library/string.html#format-string-syntax

于 2013-10-08T09:44:23.860 に答える
0

strength文字列形式の別の変数を作成します。関数を使用しstrます。

other_variable=str(strength)

次に、強さを に書​​く代わりに、代わりmyFileに使用other_variableします。

myFile.write(other_variable)
于 2013-10-08T09:55:14.723 に答える