[Tutor] Dynamically assign variable names to tuple objects
joel.goldstick at gmail.com
Tue Mar 1 20:09:39 CET 2011
On Tue, Mar 1, 2011 at 1:59 PM, Sean Carolan <scarolan at gmail.com> wrote:
> > I saw in your follow-up that you went straight for vars(). I really
> > don't think that's what you wish to use. Get rid of vars(), he had
> > to go to jail. Don't go visit vars() again for at least two months,
> > then maybe he'll be out on probation.
> Thanks Martin and Hugo. As you can tell I'm no python guru. Maybe I
> should take a step back and explain exactly what it is I'm trying to
> do. I know this can be done quickly with awk or even perl but I want
> to get more practice with python. So here's the basic idea:
> Take an arbitrary number of text files. Assume that each text file has
> the exact same number of lines. Concatenate each line of each file
> with the corresponding lines of the other files and output the data.
> So in other words, the first line of output will be
> file1_line1+file2_line1+file3_line1, etc.
> I'll work on this some more and see what I can come up with.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
Just some quick ideas:
Read about Generators. Using Hugo's snippet for reading a file a line at a
time, you can write a function to yield a single line of the file for each
call. Do this for as many files as you are combining, and concatinate the
lines each pass. Then write to your outfile
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor