Python Forum
Lists first item is a number however i cant compare it with an int getting syntax err - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Lists first item is a number however i cant compare it with an int getting syntax err (/thread-26141.html)



Lists first item is a number however i cant compare it with an int getting syntax err - Sutsro - Apr-22-2020

Hello everyone,

when i try to compare list first element i am getting a syntax error. "if satırsayısı2=isimsatırlistesi[0]" this list is made of " isimsatırlistesi.append(int(satırsayısı))" so all the elements of the list are int not sure how to avoid this. Any suggestions ?


fhand=open("arb1.txt")

satırsayısı=0
isimsatırlistesi=list()
for line in fhand:
    satırsayısı=satırsayısı+1
    if line.startswith("Adres"):
        isimsatırlistesi.append(int(satırsayısı))

adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)



RE: Lists first item is a number however i cant compare it with an int getting syntax err - anbu23 - Apr-22-2020

Use ==
if satırsayısı2==isimsatırlistesi[0]: 



RE: Lists first item is a number however i cant compare it with an int getting syntax err - Sutsro - Apr-22-2020

Still getting the error thanks for the comment tough.


RE: Lists first item is a number however i cant compare it with an int getting syntax err - anbu23 - Apr-22-2020

I am able to run your code without error

This code wont print anything due to satırsayısı2=satırsayısı+1
 adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)



RE: Lists first item is a number however i cant compare it with an int getting syntax err - Sutsro - Apr-22-2020

Thanks alot looks like i forgot to use ":" at the end of if. It works thanks a bunch :).
if satırsayısı2==isimsatırlistesi[0]:

(Apr-22-2020, 09:58 AM)anbu23 Wrote: I am able to run your code without error

This code wont print anything due to satırsayısı2=satırsayısı+1
 adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)

Thanks for the heads up :)

now it is " satırsayısı2=satırsayısı2+1"