[Ilugc] gawk query - csv processing. moving away from MS-Access

  • From: a.kumar@xxxxxxxxxxxxxxxxx (Kumar Appaiah)
  • Date: Tue Nov 3 23:52:03 2009

On Tue, Nov 03, 2009 at 07:45:42PM +0530, steve wrote:

f = open('Customer_IDs', 'r')
customer_ids = f.read().strip().split('\n') # Assuming each ID is present in 
a separate line.

small bug in the line above. The line above only strip()s the last 
newline. So, all lines except the last still retain their '\n'.

Blame incomplete testing.

Then, in your previous program, print only if the customer ID belongs
to one the above list, i.e.

if customer_id in customer_ids:
     print ...
and due to the bug above, the condition block is only entered when 
customer_id is the same as the one in the last line of the file (since 
all the other strings in customer_ids have a '\n')

Yes, thanks for pointing this out. Even I felt I rushed sending in the
mail, after I read the better suggestions.

Thanks for pointing this out.

Kumar
-- 
Kumar Appaiah

Other related posts: