473,396 Members | 1,915 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.

regular expression

Hi all,

I wrote a little program. Here it is:

import sys
import Mk4py

db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")

def func(row):
try:
if row.Nachname[0:1]=='G':
return 1
else:
return 0
except AttributeError:
return 0
vf = vw.filter(func)

for r in vf:
print vw[r.index].Nachname,vw[r.index].Kongressbereich
I create a database that contains a table. 'Nachname' and
'Kongressbereich' are special fieldnames. This program can search for
a special letter. In my example it is 'G'. and the search takes place
in 'Nachname'.
Mow I want to use regular expression. So that I can limit my search.
For example: I can search for Ge and it is not relevant wich letters
follow
Could somebody help me with this task?

Wiebke
Jul 18 '05 #1
2 2222
Wiebke Pätzold wrote:
On Thu, 31 Jul 2003 14:24:01 +0200, Thomas Güttler
<gu******@thomas-guettler.de> wrote:
Wiebke Pätzold wrote:

Please cut unimportant parts if you reply.
Can you tell me please on wich place in my program the if-statement
will be inserted?
At the same place where you have it (if ...=="G")
And then I have another question too. After the if statement there
must be a print statement. I have no idea how I must write my program
so that it is right and executably.
Can you write it me exactly how this program should look like?


You seem to be running on windows ("C:\..."). I think double-clicking
on it should execute it.

If you want to make it executable without python installed: Have a look
at py2exe.

Since you seem to be a german: Maybe my Python introduction helps you:
http://www.thomas-guettler.de/vortra...nfuehrung.html

thomas
Jul 18 '05 #2
On Thu, 31 Jul 2003 10:46:59 -0500, Jeff Epler <je****@unpythonic.net>
wrote:
These are all untested, because I don't have Mk4py or your datafile to
try it on.

I might write this:
import re
pattern = re.compile("^Ge")
def func(row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return pattern.search(nachname) is not None

vf = vw.filter(func)

If you're using a Python version with nested scopes, you could use them
in this case:
import re
def make_func(pattern):
pattern = re.compile(pattern)
def func(row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return pattern.search(nachname) is not None
return func

vf = vw.filter(make_func("^Ge"))

or you can make a callable filter object by using classes:
import re
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("^Ge"))

Jeff


thank you for the part of the program.
But I have one question.
If I insert your first suggestion- there is print nothin. Is it
possible that there is missing something?

Jul 18 '05 #3

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
1
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "":...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.