Im getting an error wile using a condition on a column two of a csv file. The error says:
TypeError Traceback (most recent call last)
<ipython-input-108-e0c74da932d1> in <module>()
6 gene = columns[2]
7 length = columns[3]
----> 8 gen_seq_length = len(seq)
9 gen_seq_length = int(gen_seq_length)
10 if gen_seq_length >= 90 and gen_seq_length <= 110:
TypeError: 'str' object is not callable
My file contains 4 coulmns: Specie_Name Sequence Gene_name Gene_count
My code is:
data = open ("data.csv")
for column in data:
columns = column.split(",")
names = columns[0]
seq = columns[1]
gene = columns[2]
length = columns[3]
gen_seq_length = len(seq)
if gen_seq_length >= 90 and gen_seq_length <= 110:
print (gene)
And i want to Print out the gene names for all genes between 90 and 110 bases long.
Can anyone help?
I'd recommend avoiding keywords as variable names. For example, your code has
length = columns[3]
, which might override any function that's also calledlength()
. Maybe usexyz_length =
I did change this variable earlier it was pos but i was getting same error
Hello angelshiza ,
the code you are showing cannot be the (complete) one, where the error message is shown. In the message this line is shown:
gen_seq_length = int(gen_seq_length)
which is missing in the code.Could you please provide a full code example and input file with which one can reproduce the problem?
Thanks,
fin swimmer
The error was i assigned variable name with len and length which are already pre-built functions due to which i was getting an error. But now my problem is solve after changing variable names.
Secondly, gen_seq_length = int(gen_seq_length) this line was in my code i commented it .