Re: [Tutor] Creating one file out of all the files in a directory

2010-11-14 Thread Josep M. Fontana
>> Again, thanks a lot. Too bad you and Kushal don't live close. I would >> like to invite you to a beer or a coffe or something. > > Thanks for the offer. Some time ever in the far, far future perhaps ;-). Well, if you or the other people who have been so helpful to me in this list ever happen to

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-14 Thread Josep M. Fontana
Thanks Alan, why is it better to open the output file outside the entire >> loop. > > Because you only need to open it once and leave it open. > You are opening it each and every time which is wasteful. > It could on some OSDS also lead to problems. And if you > were writing a new file rather tha

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-14 Thread Alan Gauld
"Josep M. Fontana" wrote OK, I ask you (or anybody reading this) the same question I asked Kushal: why is it better to open the output file outside the entire loop. Because you only need to open it once and leave it open. You are opening it each and every time which is wasteful. It could on

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-14 Thread Evert Rol
> Again, thanks a lot. Too bad you and Kushal don't live close. I would > like to invite you to a beer or a coffe or something. Thanks for the offer. Some time ever in the far, far future perhaps ;-). > >> So close ;-). >> What you're missing is the next write statement: >> f.write(data) >> >>

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-14 Thread Josep M. Fontana
Hi Evert, Again, thanks a lot. Too bad you and Kushal don't live close. I would like to invite you to a beer or a coffe or something. >> >> - code >> import os >> path = '/Volumes/DATA/MyPath' >> os.chdir(path) >> file_names = glob.glob('*.txt') > > You don't use file_nam

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-14 Thread Josep M. Fontana
Hi Kushal, First of all, thanks a lot for your help. > > Your current code adds the marker line to the original files. Is that > intended? Well, no, this wasn't intended. The part of the code that did that was introduced in one of the many attempts to solve the problem. I knew that this was an

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-11 Thread Kushal Kumaran
- Original message - > Hi, > > I'm trying to create a script to do the following. I have a directory > containing hundreds of text files. I need to create a single file with > the contents of all the files in the directory. Within that file, > though, I need to create marks that indicate

Re: [Tutor] Creating one file out of all the files in a directory

2010-11-11 Thread Evert Rol
> I'm trying to create a script to do the following. I have a directory > containing hundreds of text files. I need to create a single file with > the contents of all the files in the directory. Within that file, > though, I need to create marks that indicate the division between the > contents of

[Tutor] Creating one file out of all the files in a directory

2010-11-11 Thread Josep M. Fontana
Hi, I'm trying to create a script to do the following. I have a directory containing hundreds of text files. I need to create a single file with the contents of all the files in the directory. Within that file, though, I need to create marks that indicate the division between the contents of each