Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > grabbing portions of a file to output files

Reply
Thread Tools

grabbing portions of a file to output files

 
 
s99999999s2003@yahoo.com
Guest
Posts: n/a
 
      05-22-2006
hi.
I have a file with this kind of structure:

Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..........
......
......
xxxxx
Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
....
.....
....
xxxxx
Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
......
.....
and so on....lines starting with 'H' are headers. I wish to get the
parts of the file
where line start with 'H' all the way till before the next 'H' and save
to files of different names...how is the best way to do it ?
thanks

 
Reply With Quote
 
 
 
 
Kent Johnson
Guest
Posts: n/a
 
      05-22-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> hi.
> I have a file with this kind of structure:
>
> Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> .........
> .....
> .....
> xxxxx
> Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> ...
> ....
> ...
> xxxxx
> Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> .....
> ....
> and so on....lines starting with 'H' are headers. I wish to get the
> parts of the file
> where line start with 'H' all the way till before the next 'H' and save
> to files of different names...how is the best way to do it ?
> thanks


Something like this?

out = None
for line in open(...):
if line.startswith('H'):
if out:
out.close()
out = open(..., 'w')
if out:
out.write(line)
out.close()

Kent
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading portions of a wave file Nadie Python 1 08-16-2005 06:56 PM
Reading portions of the web.config file Jeremy Chapman ASP .Net 1 06-22-2005 10:07 PM
validating portions of asp.net page. ani ASP .Net 7 01-05-2004 10:19 PM
Setting Time or Date Portions of a Date data type Kevin Buchan ASP .Net 2 12-01-2003 05:45 PM
possible to create a control that adds portions of itself different places? Christian H ASP .Net 0 08-08-2003 10:53 AM



Advertisments