[Tutor] Script to search in string of values from file A in file B
d at davea.name
Thu May 10 12:32:31 CEST 2012
On 05/10/2012 04:20 AM, Afonso Duarte wrote:
> Dear All,
> Thanks Joel and Walter, both solutions worked nicely and produced the desired final objective!
> Short answer to Alan Gauld, far from me to start answering all your points, but I guess I should answer to the most pertinent ones:
>>> I'm not sure what you mean.
>>> The answers you got seem to have provided the answers to your questions.
> The answers that solved the problem were only given after I sent the email you answered ... the replies before that (sure you can still see them online) are aimed (I am assuming) at a more advanced level of Python not for a new guy, moreover once those were given and once i started asking how actually that could ever work I got answers arguing that the answer was given...
I must have missed several of those messages you're referring to. I've
reviewed all of them, and haven't seen any that argued "the answer was
given." The only thing I see like that is Mark Lawrence's mail that
simply pointed out the shadowing of the 'object' class. Doesn't sound
too argumentative to me.
Since your frustrated post was sent in reply to mine, I have to assume
that something about mine didn't work for you. The "advanced concepts"
were iter() and next(), both very useful Python constructs. If you
didn't understand them, why not ask about them? next() is there
precisely to solve problems of this type. Using that approach gives you
two named variables, one for the even numbered lines, and one for the
Or perhaps you were frustrated by my comment about having an even number
of lines in the B.txt file. Your response was that you can't be sure of
that. Well, every sample code in this thread had the same limitation;
they'd blow up if you gave them an odd number of lines.
Or perhaps you were annoyed that my fix for that involved reading the
whole file into memory. Well, so did every other sample, including your
original one. it did NOT involve writing anything to the file on disk,
nor was it slow to append a line to the end of an in-memory list. And
if Walter's assumption about the keyline is correct, then my first
solution didn't involve reading the whole B.txt into memory at once.
Were you frustrated that I asked questions about the files?
Clearly, both Walter and Joel had different conclusions about the file
format than I. For example, Joel's solution will find a key if it
happens to appear somewhere inside the data line for a different key.
And Walter's makes the assumption that the keyline contains exactly the
key, and not other text as you had told me. Both of them assume that
there will not be a match on the last line of the B.txt file.
Clearly I messed up somewhere, but I don't see it.
More information about the Tutor