Issue
I dont understand why my if condition is not getting executed in python.` values inside my text file are
0.000 0 0.001 1 0.002 2
f = open(sys.argv[1],"r").readlines()
var=0
for line in f:
new = f[var].split()
Time = new[0]
rev=float(new[1])
var=var+1
if 0.001 > Time :
print " I am here "
Solution
Guess you should rewrite your code:
filename = sys.argv[1]
with open(filename) as f:
for line in f:
time, rev = map(float, line.split())
if time < 0.001:
print("I'm here")
You tried to compare string (Time
variable) with float (0.001
) - it's wrong. In python 2 it's ok, but always False
. I recommend you to start using python 3 - you can't compare floats with strings with this version:)
Answered By - Lev Zakharov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.