Captain Dondo wrote: > I have an array(?) (sorry, I'm new* to python so I'm probably mangling > the terminology) that looks like this: > > [((1028L, datetime.datetime(2006, 5, 30, 7, 0), datetime.datetime(2006, > 5, 30, 7, 30), 'Arthur', 'Prunella Sees the Light; Return of the > Snowball', 'Prunella prepares for a sleepover with Marina; D.W. protects > a snowball.', 'Children', 'tooth.seiner.lan', None, 0L, None, 1L, 1L, > 'Default', 9L, 'SH044107', 'EP0441070123', datetime.datetime(2006, 5, > 30, 7, 31, 24), 1164179392L, 0.0, 1, datetime.date(2002, 11, 28), 0, 0L, > 0),), ((1028L, datetime.datetime(2006, 5, 4, 10, 0), > datetime.datetime(2006, 5, 4, 10, 30), 'Bob the Builder', 'Using Clues', > '', 'Children', 'tooth.seiner.lan', None, 0L, None, 1L, 1L, 'Default', > 6L, 'SH326087', 'EP3260870141', datetime.datetime(2006, 5, 4, 10, 31, > 30), 1163673536L, 0.0, 1, datetime.date(2005, 3, 19), 0, 0L, 0),)] > > I want to replace every instance of 'tooth.seiner.lan' with 'localhost'. > There may be lots and lots of these entries (they're pulled from my > mythtv database). > > I could brute-force this by rewriting the whole thing and replacing > every 9th element but there has to be a better way.... > > I've looked at various search-and-replace snippets but none that address > what I am trying to do.... > > --Yan > > *I'm not really new to python, just very very rusty. Last time I used > it was about 3 years ago, and I was equally clueless....
There's a lot of parenthesis :) not easy to read, but unless I'm seeing something odd, you have string literals in a tuple. So I don't think your going to find a better way than brute force recreation. FYI lists are between [] and are mutable Tuples are between () and are immutable. If I'm countin paren's right you have a list that contains a tuple, that contains another tuple with 1 element in it. so you can recreate the tuples... or convert the whole thing to a list of lists. -- http://mail.python.org/mailman/listinfo/python-list