Text file extract
bbeck at NOSPAM.austin.rr.com
Sun Sep 7 19:30:02 CEST 2003
I wrote a generalized version of this exact thing a year or so ago. It
can be found at:
Additionally a post I made about it from last year can be found at:
Specifically you'll want to write something like what's contained in
FirstNameSplitter.py but for your CSV format. Here's what I suggest you
make YourSplitter.py look something like.
re_group_name = re.compile('[^,]*,[^,]*,(?P<name>[^,]*),.*')
def get_group_name(self, line):
def get_group_filename(self, groupname):
return groupname + '.txt' # You'll want to update this to
specify your subdirectory too
def update_line(self, line):
return line # no need to modify the line
Once that's done you can run 'python splitter.py YourSplitter input.txt'
and it should just work its magic.
"Andy" <Hoosbruin at Kconline.com> wrote in message
news:1PudndLL4fUZWMqiU-KYuA at kconline.com...
> I have a test file and need to split the data based upon a record in a
> certain field. Then write those record to a multiple files in
> Example data:
> RECORD 1) ABCD,666,TOM,4.00,9/1/03
> RECORD 2) TYTY,666,TIM,4.00,9/1/03
> RECORD 3) ABCD,666,BILL,4.00,9/1/03
> RECORD 4) XXXX,666,TOM,4.00,9/1/03
> All the fields will be comma separated and the 3rd field will contain
> record I will use to split.
> So records 1 and 4 get written to the same file call it Cust.txt and
> it to folder \\server\tom\Cust.txt
> Then record 2 gets written to cust.txt in a different folder
> and so on.....
> I have never written a Python script so would like to see how this
> done. I deal with a lot of text file input and would like to see how
> Python handles this task..
> thanks in advance... If you could doc some of your code so I can
> thru it .. would be great.
More information about the Python-list