[Tutor] (no subject)

John Fouhy john at fouhy.net
Fri Sep 15 01:17:30 CEST 2006


On 15/09/06, timothyh at email.arizona.edu <timothyh at email.arizona.edu> wrote:
> This is the first time I have posted to this list so I hope I am asking
> appropriate question in acceptable way. Want I want to do is take a file and
> cut it into pieces so each piece is a new unique file; the new files would be
> one line (newline) from the file I want to cut up. The file  I want to cut up
> has 3900 lines. This is as far as I have got.

So, you want to create 3900 different files, then?

What do you want to call these files?

You can iterate through each line of a file like this:

input = open('/Users/timothy/Desktop/t' , 'r')
for line in input:
    # ...

So, in the body of the for loop, all you would need to do is decide
what to call the new file, open the file, write line to it, and then
close it.

-- 
John.


More information about the Tutor mailing list