ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: scanf style parsing
by Andrei Kulakov other posts by this author
Sep 26 2001 10:21PM messages near this date
Re: scanf style parsing | Re: scanf style parsing
On Wed, 26 Sep 2001 05:42:45 GMT, Bruce Dawson <comments@[...].com>  wrote:
>  I love programming in Python, but there are some things I have not found
>  the easy way to do. I understand that Python is supposed to be good at
>  text parsing, but I am having trouble with this simple task. Given this
>  text (the output from VisualC++) I want to find out how many errors and
>  warnings there were:
>  
>  smtpmail.exe - 0 error(s), 0 warning(s)

Seeing that there should only be 2 words here that are numbers, you can do
this:

my_str # that's where the result is
words = my_str.split()
lst = []
for word in words:
    try:
        result = int(word)
        lst.append(result)
    except:
        pass

errors = lst[0]
warnings = lst[1]

I'm not sure how can this format vary, but if these numbers are always at
the same place, you could have just done:

errors, warnings = int(words[2]), int(words[4])

- Andrei 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Bruce Dawson
Skip Montanaro
George Demmy
Hans-Peter Jansen
Quinn Dunkan
Tim Hammerquist
Ralph Corderoy
Toby Dickenson
Duncan Booth
Aahz Maruch
Aahz Maruch
Aahz Maruch
Stefan Schwarzer
Grant Edwards
Fredrik Lundh

Malcolm Tredinnick
Ralph Corderoy
Tim Hammerquist
Stefan Schwarzer
Greg Ewing
Skip Montanaro
Boyd Roberts
Steve Clift
Bruce Dawson
Tim Hammerquist
Tim Hammerquist
Tim Hammerquist
Skip Montanaro
Andrew Dalke
Fredrik Lundh
Oleg Broytmann
Andrei Kulakov
Duncan Booth
Chris Barker
Tim Hammerquist
Skip Montanaro
Jon Nicoll
Oleg Broytmann
Bruce Dawson
Skip Montanaro
Andrei Kulakov
Richard Jones
Skip Montanaro
Andrew Dalke

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved