abstraction of the column names (classes)
wiebke.paetzold at mplusr.de
Wed Aug 6 09:51:36 CEST 2003
On 5 Aug 2003 14:00:23 -0700, p-abel at t-online.de (Peter Abel) wrote:
>Wiebke Pätzold <wiebke.paetzold at mplusr.de> wrote in message news:<h29viv0b74ib3tc1g7eem3eo26fsjv93bj at 4ax.com>...
>> Hi all!
>> I create a database that contains a table. 'Nachname' is one of 13
>> column names. This program can search for
>> a special letter. In my example it is 'ra'. and the search takes place
>> in 'Nachname'. 'ra' takes place within a word. This is solved with
>> regular expression. So that I can limit my search.
>> For example: I can search for 'ra' and it is not relevant wich letters
>> follow or wich letters are in front of 'ra'.
>> Now I want to abstract the column name 'Nachname'. So I search in an
>> unknown column. Only the user of the program should determine in wich
>> class the search takes place. This input should happen in the view
>> lines of testing the class.
>> My task is it to change the program that a abstraction of the column
>> names takes place.
>> Please give me a detailed answer. If it is possible the changed
>> program because I am very new in Python and I am orientationless.
>> This is the program
>> import sys
>> import Mk4py
>> import re
>> db = Mk4py.storage("c:\\datafile.mk",1)
>> vw = db.view("people")
>> class PatternFilter:
>> def __init__(self, pattern):
>> self.pattern = re.compile(pattern)
>> def __call__(self, row):
>> nachname = row.Nachname
>> except AttributeError:
>> return 0
>> return self.pattern.search(nachname)is not None
>> vf = vw.filter(PatternFilter("ra.*"))
>> for r in vf:
>> print vw[r.index].Nachname
>RegEx are really great and there are a lot of problems you can
>only solve with them. But if I understand you right your problem
>is to find a string where a substring is to be in, the simple
>string operation does the work:
>if String.find(substring) > -1:
>**find** will give you the position in String where substring
>will occure the 1rst time and -1 if substring doesn't occur.
>>>> nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller']
>>>> for name in nameList:
>... if name.find('er')>-1:
>... print name
>So if you can get your columns contents in **ColumnList**
>and your searchpattern in **SearchPattern** so the following
>function could do the work:
> for n in ColumnList:
> if n.find(SearchPattern) > -1:
> return foundList
I think you didn't understand me. My task is:
I have a database that consists of a tabla with different columns. The
program should have two possibilities to search for regular
expressions. The firat one possibility is in this program. Here I can
look for a certain expression. In my example I can look for 'ra' and
it is not relevant wich letters follow or wich letters are in front of
'ra'. But this search can ONLY takes place in the column 'Nachname'.
'Nachname is fixed by the programmer.
The second possibility is that the user and NOT the programmer
determine the column name in which the user want to look for a regular
expression. And so I think there must be anything with a print. Only
like that the user can enterin what column the search takes place.
More information about the Python-list