473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

classes (table)

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'.
This is the program that I wrote:

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):
try:
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
The program should have two possibilities to search for regular
expressions. The first 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. Only the user can determine in which column the search
takes place.
These 2 kinds of the search must be combined in the program.

I hope somebody can help me with my problem!

Wiebke

Jul 18 '05 #1
4 1643
Wiebke Pätzold wrote:
...
import Mk4py
I'm not experienced in this package, so I'm not sure this will
work and can't test, but:
def __call__(self, row):
try:
nachname = row.Nachname


Just change this to

whatever = getattr(row, self.attributeName)

Where self.attributeName can be any string, e.g. defaulting
to 'Nachname' if you wish, as set e.g. in __init__.
Alex

Jul 18 '05 #2
On Wed, 06 Aug 2003 11:31:39 GMT, Alex Martelli <al***@aleax.it>
wrote:
Wiebke Pätzold wrote:
...
import Mk4py


I'm not experienced in this package, so I'm not sure this will
work and can't test, but:
def __call__(self, row):
try:
nachname = row.Nachname


Just change this to

whatever = getattr(row, self.attributeName)

Where self.attributeName can be any string, e.g. defaulting
to 'Nachname' if you wish, as set e.g. in __init__.
Alex


but the user of the program should have the possibility to select in
wich column the search takes place.

On the one hand the program must be in the situation to search in all
columns of the table for a special word. And on the other hand the
user have to determine in wich column the search after this special
word takes place. This is the task. And this two things must combined
in one program.

Jul 18 '05 #3
> def __call__(self, row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return self.pattern.search(nachname)is not None


You should probably start by rewriting your basic function as

def search_call (self, row, column):
if not hasattr(row, column):
return 0 # No such column
nachname=getattr(row, column)
return self.pattern.search(nachname) is not None

Now you can choose the column at will within the program.
(nachname is now a poor choice of variable name)

To restrict access to columns, restrict this function and provide as a
public function the following:

def __call__ (self, row):
return search_call(row, 'Nachname')

Hope this helps.

MfG
Christopher Boomer.
Jul 18 '05 #4
On Wed, 2003-08-06 at 13:49, Wiebke Pätzold wrote:
but the user of the program should have the possibility to select in
wich column the search takes place.


If you're not willing to start thinking Python and read some
documentation before asking questions as these (have you ever seriously
programmed before? If not, go read the tutorials on
http://www.python.org), I guess there's no reason I'd help you. Unless
you pay for my programming time, of course...

Heiko.

PS: I know Alex Martelli has answered already, but I just thought that
it might be worth noting that Wiebke is simply asking the group to write
a program she needs, which is not what I think comp.lang.python is
for...
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
12
by: bissatch | last post by:
Hi, Generally if I re-use code, I use a function. If I need to use these functions over a number of pages I write the function to an include file where all pages have access. So when should I...
4
by: Axel Straschil | last post by:
Hello! I was fooling around with creating classes for a module with eval, something like: MyModule.py: class Base: init(self, name): self._name = name
2
by: yackel | last post by:
Hi there, I'm just in the paper-designing stage of an inventory / sales database but am looking for some help and suggestions as it seems a little out of the norm due to the different classes of...
4
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to...
0
by: Jim Stools | last post by:
Hopefully this will make some sense.. I have a database that has around 50 tables - I thought about putting each table in a class and the data connection in a class then I could manage the (tables)...
4
by: Jim Stools | last post by:
Forget the re-post I had my clock set 12 hours earlier Hopefully this will make some sense.. I have a database that has around 50 tables - I thought about putting each table in a class and the...
14
by: Mark S. | last post by:
Hello, I've written a high performance web app with C# and it completely relies on static hash tables (using sync) and classes. Under real world stress this app is handling 5 get requests per...
8
by: =?Utf-8?B?cmljaEI=?= | last post by:
I am trying to build a rating engine for a number of users for a list of songs. I havea database design with a user table and a song table and a link table such that each user can rate many songs...
3
by: Glenn | last post by:
My current classic-ASP site has users, projects, roles and the 2.0 membership looks like a perfect fit, but I'm having trouble finding examples of how to have users that belong to different...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.