On Thu, Jul 30, 2009 at 4:49 PM, Sander Sweers<sander.swe...@gmail.com> wrote: > 2009/7/30 Eduardo Vieira <eduardo.su...@gmail.com>: > > With == you are testing if the 2 values are exactly the same. So 'one' > == 'one' will return True but 'one; == 'one two' will return False. > > With in you test if the value is part of a another value. So using the > same value as above 'one' in 'one' will return True but 'one' in 'one > two' will also return True as 'one' is part of the second string. > > The same logic applies to lists and dicts. 'one' == ['one', 'two'] > will return False as the the 2 values are not exactly the same but > 'one' in ['one', 'two'] will return True. > >> # this does not work: >> for row in sitelist: >> for line in bvreaderone: > > If you are getting unexpected results add in print statements to see > what is the data that you are working with. I would add the below 2 > print statements to see what you are now actually comparing. Same > applies to the other working example. > : > print 'Value row['EMAIL'] is: %s' % row['EMAIL'] > print 'Value of line['BVADDREMAIL'] is: %s' % line['BVADDREMAIL'] > >> if row['EMAIL'] == line['BVADDREMAIL']: > > Here you are testing if the value of row['EMAIL'] is exactly the same > as line['BVADDREMAIL']: which is not the case so the test returns > False and the below print statement is not executed. > >> print line['NAME'], row['COMPANY'] >> >> # but this does work: >> for row in sitelist: >> for line in bvreaderone: >> if row['EMAIL'] in line['BVADDREMAIL']: > > Here you test if the value row['E_MAIL'] is part of > line['BVADDREMAIL']:which is True. > >> print line['NAME'], row['COMPANY'] > > Someone did a way better job writing this down some time a go but > can't find the post online. I hope you see now what the difference is > between the 2. Thanks for pointing out this, Sander. Yes, a print statement revealed the right after commas... In this case I should enable the option from the csv module to ignore such white spaces.
Eduardo _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor