1

I am working with Python plugins.
I have my list called station_list ,to which i had appended all the values.It contains all the integer values.
Now,I wanted to check my query result with list content. My code is:

self.db._exec_sql(c, "select distinct (station) from station  ")
for row in c.fetchall():
    for m in range(len_station_list):
        print row[0],station_list[m]

        if row[0] == station_list[m]:
                print 'true'

I am checking each selected row with list values. When i print and check, it gives correct answer.But comparision goes wrong.
It does not satisfy condition if row[0] == station_list[m]:.
What can be the problem?

1
  • Can you post the output from the print row[0],station_list[m] line, so we can see why the if fails? Commented Feb 27, 2012 at 8:31

1 Answer 1

1

Try this.

x = self.db._exec_sql(c, "select distinct (station) from station  ").fetchall()

y = [p for p in x if p[0] in station_list]
Sign up to request clarification or add additional context in comments.

3 Comments

Thanx for helping..p[0] checks for only one row.How to check for all rows?? and what does y contains??
@user1111283 That's not true. p[0] checks for the first member (field) of each row. y contains all rows for which the first member is in your station_list - which should better be a set, not a list.
@user1111283 the code in [ ] brackets is called a list comprehension - it will iterate through all the items in x and build a list containing all items in p where p[0] is in station_list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.