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 Chris Barker other posts by this author
Sep 27 2001 5:53PM messages near this date
Re: scanf style parsing | Re: scanf style parsing
Bruce Dawson wrote:

>  Rather than the long and complicated PEP route of adding scanf
>  style functionality to Python it would probably be enough to just add some
>  more examples to the Python regexp documentation. I searched the Python
>  documentation for scanf() and I looked at the regexp documentation, so if
>  it had contained the examples in this reply or others I would have done
>  my parsing properly long ago.

I completely disagree: scanf-type functionality is by no means a
replacement for REs or vice-versa. I'm not all that familiar with scanf,
but from what I have seen, it is really only useful for very simple text
scanning, mostly to extract numbers from strings (or files). When scanf
would work well, Python's string functions would generally work just
fine (see the examples given in this thread--much easier than the re
methods!). When regexs are warranted, scanf would be useless.

That being said, I am a strong advocate of adding some kind of
scanf-type fuctionality to Python, so that it can be used for what it is
good for: extracting numbers from fairly rigidly formated text. This can
be done well with string methods. I have a lot of code similar to:

for line in file.xreadlines():
	data.append(map(float,line.split()))

This is kind of clunky, and very slow if you have a lot of data. I'd
really like a cleaner, faster way of doing this kind of thing. I know
there are some routines in SciPy that help, but a more native approach
would be nice.

-Chris



-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker@[...].net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------
-- 
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