Len on a row in csv

-I am out of ideas, can sombody help

if (len(row[34]) > 90 and (row[18]) == ‘980000’):
tekst = ‘Test of code’ # there is a tab in front here

print (row[34]) = 120 char.
print (row[18])= 980000
print (tekst)= old txt, nothing change

I think we’re missing the wider programme, for example I don’t know what
would be in tekst. Please paste in sufficient code to run.

Also, how are you reading the CSV data? Normally you would use
csv.reader from the 'csv" module, and most CSV files present numbers as
numbers. So your rowp18] might be the number 98000 and not the string
‘98000’. Just guessing here.

Print out repr(row) to see which fields are strings and which are

You don’t need brackets around row[18] or row[34].

The brackets in the print lines are for the print() function call
itself, not the row part.

Try printing repr(row[18]) and repr(row[34])

Does row[34] have a very long string of text in it?

Put a print() inside the if-statement and before the if-statement:

print("len(row[34]) =", len(row[34]))
print("row[18] =", repr(row[18]))
if (len(row[34]) > 90 and (row[18]) == '980000'):
    print("IF IS TRUE")
    tekst = 'Test of code'      # there is a tab in front here

to check that the columns have the values you’re expecting to find. If
the if-statement is not setting tekst, then like the columns have values
other than what you anticipate.

Remember that in Python lists count from 0, so row[18] references the
19th column (because there is a row[0], being the first column).

Cameron Simpson cs@cskk.id.au

Thank you Cameron,

-the fault was that I run 'print(row)'in the conslole, before one of the rows was replaced with the ‘tekst’ variable, so the file was OK.

Some times you get blind on your own code…