Matching a constant string at beginning
François Pinard
pinard at iro.umontreal.ca
Wed Dec 22 21:03:37 EST 1999
Hello, people. Some have a nice idiom for the following?
I first wrote, a few months ago by now, I guess:
if re.match('Simonsen', line):
and to later speed up things a little, for some little while:
if line[:8] == 'Simonsen':
Yet, computing that `8' index is tedious, and writing:
if line[:len('Simonsen')] == 'Simonsen':
is rather tedious. Of course, I could write a very small function to
match a constant string at the beginning of another, but there just must
be some idiom for doing this.
I also tried:
if string.find(line, 'Simonsen') == 0:
but this scans the whole line for nothing, this is not better.
So, do I have no choice then write that very small function? :-)
--
François Pinard http://www.iro.umontreal.ca/~pinard
More information about the Python-list
mailing list