newbie problem

Matt Gerrans matt_gerrans at hp.com
Tue Aug 27 20:10:14 CEST 2002


How's this (I saved your sample input to a file called c:\temp\input.dat,
obviously):

for line in open( r'c:\temp\input.dat' ).readlines():
   len(line.split()) > 2:
      if line.split()[0]=='#':
         tag=line.split()[2]
      else:
         print '|'.join([tag]+line.split())

(This is quick 'n' dirty, of course, if I was *really* going to use it,
there would be a bit of error handling and it wouldn't be using hard-coded
filenames, etc., but it is good enough for one-shot use, if you are just
using it yourself (I think -- you can see how badly it falls apart on your
real data file!).)

"Manuel Hendel" <manuel at hendel.net> wrote in message
news:mailman.1030451855.5998.python-list at python.org...
> On Tue, Aug 27, 2002 at 08:06:43AM -0400, Peter Hansen wrote:
> >
> > Do you want the experience of figuring most of this out yourself, so
> > we should provide hints, or do you want a ready-made solution which
> > gets the job done, and from which you can learn for next time?
> >
> > This is only about a ten or fifteen line program, if that, I think,
> > so it's probably pretty easy for us to post a full working version
> > if you wish.
>  To be honest, I would prefer the one from which I could learn for
>  next time? :-)
>  During the time I wrote my mail and waited for an answer, I tried to
>  get this started, I'm getting more and more confused. I would be very
>  happy if you can provide me with this program.
>
>  Thank you very much in advance,
>     Manuel
>
> --
> Calling you stupid is an insult to stupid people!
> -Wanda, "A Fish Called Wanda"
>





More information about the Python-list mailing list