N00b question: matching stuff with variables.
Ken D'Ambrosio
ken at jots.org
Mon Jun 28 13:29:35 EDT 2010
Hi, all. I've got a file which, in turn, contains a couple thousand
filenames. I'm writing a web front-end, and I want to return all the
filenames that match a user-input value. In Perl, this would be something
like,
if (/$value/){print "$_ matches\n";}
But trying to put a variable into regex in Python is challenging me --
and, indeed, I've seen a bit of scorn cast upon those who would do so in
my Google searches ("You come from Perl, don't you?").
Here's what I've got (in ugly, prototype-type code):
file=open('/tmp/event_logs_listing.txt' 'r') # List of filenames
seek = form["serial"].value # Value from web form
for line in file:
match = re.search((seek)",(.*),(.*)", line) # Stuck here
Clearly, the line, above, is just plain ol' wrong, but I'm including it to
give a hint of what I'm trying to do. What's the correct Python-esque way
to go about this?
Thanks!
-Ken
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Python-list
mailing list