[Tutor] Efficient way to join files
"Héctor Villafuerte D."
hec.villafuerte at telgua.com.gt
Wed Oct 1 16:21:59 EDT 2003
Jeff Shannon wrote:
> Bob Gailer wrote:
>
>> On Windows? os.popen("copy sourcefile1 + sourcefile2 + ...
>> destinationfile").read()
>
>
> I think that it would be a bit of a stretch to call this "more
> efficient", at least if one thinks at all about the implementation of
> this code. (Maybe this just depends on one's definition of
> "efficiency"...)
>
> You are proposing, here, to get the OS to read all the files and
> append them to another (new) file, and then read in the new file.
> That's, at a minimum, an extra hard drive read and hard drive write
> for each of those files. Using fileinput, or otherwise looping
> through a list of files, doesn't do that. This solution may take
> fewer lines of code, but LoC count isn't necessarily related to real
> efficiency in any meaningful way.
>
> I would also say that it's more clear to state, in code, "take this
> list of files and process them one at a time, with this procedure..."
> than to state "Get someone else to collect all of these files and copy
> them into a new one, and then take that new file and do this..."
>
> It is simplest to write a procedure that pretends to be dealing with
> only a single file, to be sure. However, I think that the correct
> abstraction is to have a function that is passed a single file, and
> that deals with multiple files by getting them passed to it in
> sequence, rather than to write something that handles multiple files
> by squeezing them all together into an undifferentiated mass.
I was reading that there is a Python Profiler! I'll take a look at it
and post which method resulted "more efficient".
This language is really nice! Pardon my excitement, but before Python I
only knew C/C++, assembler for PIC's and VB (which I
didn't like) This is my second week with python and I have a strong
feeling that this relationship will be a long one ;)
More information about the Tutor
mailing list