[Tutor] newbie: Reading text file

Grant Hagstrom grantahagstrom at gmail.com
Fri Jun 1 12:57:06 CEST 2007


Kent,

Your multistrip tid-bit worked perfectly. Thanks!

The reason why I didn't want the import solution is that I am learning
python because I want to parse text data. This problem was perfect practice.

Thanks for the links. I'll check them out. You don't happen to have any
parsing tutorials bookmarked somewhere do you? I'm already exploring
http://gnosis.cx/TPiP/. It's pretty heavy though.

Best,

Grant

On 6/1/07, Kent Johnson <kent37 at tds.net> wrote:
>
> Grant Hagstrom wrote:
> > Thanks for your help Alan.
> >
> > I found that when I used the code, it did returne a list but it is
> > riddled with formatting characters.
> > My question is, is it possible to strip out multiple characters at once?
>
> Yes, just pass multiple characters to strip(), e.g.
> line = line.strip('\r\n\t \'",')
>
> I'm curious why you don't like the import solution. exec and execfile()
> could also work although all three require that the file contain trusted
> data.
>
> Here are a couple of recipes that do almost what you want (you would
> still have to strip out the "jobs = " part:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/281056
>
> Kent
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/ec20d191/attachment.html 


More information about the Tutor mailing list