André a écrit :
(snip)
you don't need to use pattern.items()...
Here is something I use (straight cut-and-paste):
def parse_single_line(self, line):
'''Parses a given line to see if it match a known pattern'''
for name in self.patterns:
result =
John Machin schrieb:
No, complicated is more related to unused features. In
the case of using an aeroplane to transport 3 passengers 10 km along
the autobahn, you aren't using the radar, wheel-retractability, wings,
pressurised cabin, etc. In your original notion of using a dict in
your lexer,
Dennis Lee Bieber schrieb:
Is [ ( name, regex ), ... ] really simpler than { name: regex, ...
}? Intuitively, I would consider the dictionary to be the simpler
structure.
Why, when you aren't /using/ the name to retrieve the expression...
So as soon as I start retrieving a regex
John Machin schrieb:
Rephrasing for clarity: Don't use a data structure that is more
complicated than that indicated by your requirements.
Could you please define complicated in this context? In terms of
characters to type and reading, the dict is surely simpler. But I
suppose that under
On Nov 25, 4:38 am, Thomas Mlynarczyk [EMAIL PROTECTED]
wrote:
John Machin schrieb:
Rephrasing for clarity: Don't use a data structure that is more
complicated than that indicated by your requirements.
Could you please define complicated in this context? In terms of
characters to type and
John Machin wrote:
On Nov 25, 4:38 am, Thomas Mlynarczyk [EMAIL PROTECTED]
[...]
Judging which of two structures is simpler should not be independent
of those requirements. I don't see a role for intuition in this
process.
Maybe I should have said upon first sight / judging from the outer
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of if m, I figured maybe I could use a dictionary
to hold the patterns, and loop through it:
==
pattern = {}
pattern[pattern1] =
Gilles Ganault [EMAIL PROTECTED] writes:
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of if m, I figured maybe I could use a dictionary
to hold the patterns, and loop through it:
Gilles Ganault wrote:
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of if m, I figured maybe I could use a dictionary
to hold the patterns, and loop through it:
Good idea.
import re
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
[EMAIL PROTECTED] wrote:
But there is no reason why you should use a dictionary; just use a list
of key-value pairs:
patterns = [
(pattern1, re.compile(.+?/td.+?(.+?)/td),
Thanks for the tip, but... I thought that lists could only use
2008/11/23 Gilles Ganault [EMAIL PROTECTED]
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of if m, I figured maybe I could use a dictionary
to hold the patterns, and loop through
On Sun, Nov 23, 2008 at 2:55 PM, Gilles Ganault [EMAIL PROTECTED] wrote:
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
[EMAIL PROTECTED] wrote:
But there is no reason why you should use a dictionary; just use a list
of key-value pairs:
patterns = [
(pattern1,
On Nov 24, 6:55 am, Gilles Ganault [EMAIL PROTECTED] wrote:
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
[EMAIL PROTECTED] wrote:
But there is no reason why you should use a dictionary; just use a list
of key-value pairs:
patterns = [
(pattern1, re.compile(.+?/td.+?(.+?)/td),
On Nov 24, 5:36 am, Terry Reedy [EMAIL PROTECTED] wrote:
Gilles Ganault wrote:
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of if m, I figured maybe I could use a dictionary
John Machin schrieb:
General tip: Don't us a data structure that is more complicated than
what you need.
Is [ ( name, regex ), ... ] really simpler than { name: regex, ...
}? Intuitively, I would consider the dictionary to be the simpler
structure.
Greetings,
Thomas
--
Ce n'est pas parce
On Nov 23, 1:40 pm, Gilles Ganault [EMAIL PROTECTED] wrote:
Hello
After downloading a web page, I need to search for several patterns,
and if found, extract information and put them into a database.
To avoid a bunch of if m, I figured maybe I could use a dictionary
to hold the patterns, and
On Nov 24, 7:48 am, John Machin [EMAIL PROTECTED] wrote:
On Nov 24, 5:36 am, Terry Reedy [EMAIL PROTECTED] wrote:
print name + '#' + regex
Perhaps you meant:
print key + # + regex.pattern
I definitely meant:
print name + '#' + regex.pattern
--
On Nov 24, 7:49 am, Thomas Mlynarczyk [EMAIL PROTECTED]
wrote:
John Machin schrieb:
General tip: Don't us a data structure that is more complicated than
what you need.
Is [ ( name, regex ), ... ] really simpler than { name: regex, ...}?
Intuitively, I would consider the dictionary to be
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
[EMAIL PROTECTED] wrote:
But there is no reason why you should use a dictionary; just use a list
of key-value pairs:
Thanks for the tip. I didn't know it was possible to use arrays to
hold more than one value. Actually, it's a better solution,
Gilles Ganault wrote:
On Sun, 23 Nov 2008 17:55:48 +, Arnaud Delobelle
[EMAIL PROTECTED] wrote:
But there is no reason why you should use a dictionary; just use a list
of key-value pairs:
Thanks for the tip. I didn't know it was possible to use arrays to
hold more than one value.
On Sun, 23 Nov 2008 23:18:06 +, MRAB [EMAIL PROTECTED]
wrote:
A list is an ordered collection of items. Each item can be anything: a
string, an integer, a dictionary, a tuple, a list...
Yup, learned something new today. Naively, I though a list was
index=value, where value=a single piece of
On Mon, 24 Nov 2008 00:46:42 +0100, Gilles Ganault wrote:
On Sun, 23 Nov 2008 23:18:06 +, MRAB [EMAIL PROTECTED]
wrote:
A list is an ordered collection of items. Each item can be anything: a
string, an integer, a dictionary, a tuple, a list...
Yup, learned something new today. Naively, I
22 matches
Mail list logo