I am trying to load a text file that has two column data, separated by a tab. The first column values could be either integers or floats, while the second column will always be floats. Now, I am using isinstance
to see if my first column is integer or float. However, isinstance
doesn't seem to work when a list of values or the final element of the list is used. This is my code:
time_t = []
with open(logF, 'r') as f:
for line in f:
data_t = line.split()
time_t.append(data_t[0])
time_length_max = time_t[-1]
print time_length_max
if isinstance(time_length_max, (int, long)):
print "True"
else:
print "False"
The output I get is:
10000
False
Suppose, I declare time_length_max = 10000
, instead of time_length_max = time_t[-1]
, I get:
10000
True