Re: Using dictionary to hold regex patterns?

2008-11-26 Thread Bruno Desthuilliers
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 =

Re: Using dictionary to hold regex patterns?

2008-11-25 Thread Thomas Mlynarczyk
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,

Re: Using dictionary to hold regex patterns?

2008-11-24 Thread Thomas Mlynarczyk
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

Re: Using dictionary to hold regex patterns?

2008-11-24 Thread Thomas Mlynarczyk
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

Re: Using dictionary to hold regex patterns?

2008-11-24 Thread John Machin
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

Re: Using dictionary to hold regex patterns?

2008-11-24 Thread Steve Holden
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

Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
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] =

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Arnaud Delobelle
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:

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Terry Reedy
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Vlastimil Brom
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Benjamin Kaplan
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,

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread John Machin
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),

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread John Machin
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Thomas Mlynarczyk
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread André
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread John Machin
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 --

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread John Machin
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
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,

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread MRAB
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.

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Gilles Ganault
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

Re: Using dictionary to hold regex patterns?

2008-11-23 Thread Marc 'BlackJack' Rintsch
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