reading a line in file

Brian McCann Brian.McCann at viziant.net
Mon Aug 20 17:05:49 EDT 2007


Hi Shawn,

what if I had a file
com.properties with the below line in it

If I needed to capture the value of everything separeted by a ":"
and asign each to a variable would regex be the right method to grab those?

like 
a=jdbc
b=oracle
c=@127.0.0.1
d=1521
e:XE
 
--Brian

com.db.connstr=jdbc:oracle:thin:@127.0.0.1:1521:XE
 
 
 

________________________________

From: python-list-bounces+brian.mccann=viziant.net at python.org on behalf of Shawn Milochik
Sent: Mon 8/20/2007 4:35 PM
To: python-list at python.org
Subject: Re: reading a line in file



Although you're technically correct, I think there's a knee-jerk
anti-regex reaction, citing the meaningless overhead. If you're
running many thousands of records or something then it becomes a small
issue compared to a replace statement or something. But in most cases
it makes no difference at all.

Run the example script both ways and I'm sure there will be no
difference, and I prefer a clear regex to a convoluted (in my opinion)
substring call.

In any case, it's a preference, and I have never seen anything which
convinced me that one should avoid regexes at all costs unless there's
no other way to do it.

And the comment about solving a problem by using regular expressions
creating another problem is just asinine.  Like so many other things,
it's often repeated without any thought about whether it is true in
general, much less in the situation in question.
--
http://mail.python.org/mailman/listinfo/python-list


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070820/198c8c11/attachment.html>


More information about the Python-list mailing list