2016-07-13 8 views
0

私はテキストファイルの行から浮動小数点数を抽出しようとしていますが、浮動小数点数に行番号(str)を変換する方法を理解できません。Python String to float

フロート(linevalue)と
for line in fh: 
    if not line.startswith("A specific string") : continue 
    count = count + 1 
#linevalue gets the numbers in the line that i'm interested in, so in order 
#to have only the numeric value i tried getting rid of the other text in the line by only 
# selecting that range (20:26 
    linevalue = line[20:26] 
    float(linevalue) 
    print type(linevalue) 
    print linevalue 

試みた変換が通過していないされ、プログラムの出力は、例えばまま:

<type 'str'> 0.4323 

誰も私が私が何をしないのです理解するのに役立つことはできますか?

ありがとうございます。

答えて

3

私はあなたがしたいと思う:

linevalue = float(linevalue) 

あなたが正しくフロートに文字列値を変換したが、あなたはどこにでもその値を保存していませんでした。 (floatを呼び出すとは変更されません既存の変数です;新しい値を返します)

+0

ありがとうございます...私は今はダム感じる:)私は完全にそれを逃した – Schwarz