On Sat, Aug 7, 2010 at 8:26 AM, David Hutto <smokefl...@gmail.com> wrote: > On Sat, Aug 7, 2010 at 7:26 AM, Alan Gauld <alan.ga...@btinternet.com> wrote: >> >> "TGW" <galaxywatc...@gmail.com> wrote >>> >>> What I want to output is: >>> 12345|some text|some more text|example|example32423 >>> 11223|more text|and more|example|example455667 >>> >>> So column 4 is where the change occurs, but only if the beginning >>> of the string in column 4 =~ /^example/i # and it should be case >>> insensitive >>> >> >>> reader = csv.reader(open(filename, 'rb'), delimiter='|', >>> quoting=csv.QUOTE_NONE) >>> for row in reader: >>> print row >>> >>> .... >>> I can print the file, I just need a little help searching and replacing >>> the column 4 data element. >> >> OK, so I'm not sure which bit is confusing you. >> The reader returns a list of fields per row. >> You want the fourth column which is element 3 in row - ie. row[3] >> You can use startswith() or a regex to test the value >> You can replace the string with whatever you like since lists are mutable >> You can then store/write the modified list to whatever/wherever you like. >> >> Now which bit of that is causing you grief? > > Probably the explanation. Mainly because of lack of documentation than > google terms, Not to say that docs are laccking to the proportion of want.
and appropriate questions >> >> -- >> Alan Gauld >> Author of the Learn to Program web site >> http://www.alan-g.me.uk/ >> >> >> _______________________________________________ >> Tutor maillist - tu...@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor