copying files into one
Ten
runlevelten at gmail.com
Sun May 14 10:03:21 EDT 2006
On Sunday 14 May 2006 05:09, Gary Wessle wrote:
> Hi
>
> I am looping through a directory and appending all the files in one
> huge file, the codes below should give the same end results but are
> not, I don't understand why the first code is not doing it.
>
> thanks
>
Hi there - I think you might need to give a more whole code sample when asking
this question, as it's all a bit ambiguous - for instance "file" is a type,
like "string" or "list" but...
>
> combined = open(outputFile, 'wb')
>
> for name in flist:
> if os.path.isdir(file): continue
^If you can successfully get past this line, you must have reused "file" to
describe a string (which is probably quite a *BAD* idea ;) ) and just not
included some of the code... BUT
>
> infile = open(os.path.join(file), 'rb')
>
This line suggests it's a list, so I don't know. Argh.
Anyway, I'm not being pernickety, just pointing out that it's a little too
ambiguous - the code sample you gave alone would not work at all..
> # CODE 1 this does not work
> tx = infile.read(1000)
> if tx == "": break<<<<<
> combined.write(tx)
> infile.close()<<<<<<<<<
>
> # CODE 2 but this works fine
> for line in infile:
> combined.write(line)
> infile.close()
>
> combined.close()
Hope to help when you post back,
Cheers,
Ten
--
There are 10 types of people in this world,
those who understand binary, and those who don't.
More information about the Python-list
mailing list