Reusing block

0 views
Skip to first unread message

chiangf

unread,
Dec 9, 2006, 11:38:15 PM12/9/06
to TurboGears
I have a block of code that several functions share (with slight
modifications) and I want to put it into an external function. The
problem is that the other functions point to their own respective
tables. So in the end, I have something like this:

---------------
in class Item:
def index():
...
result = MyTableItem(item=item, ...) #item is foreign key pointing
to a table called Item
...

in class Place:
def index():
...
result = MyTablePlace(place=place, ...) #place is FK pointing to a
table called Place
...

...etc...
---------------

I want to put it into a common function but I don't know how to replace
the item=item part (or place=place) with a variable. This is what I
had in mind:

---------------
def commonFunction(myDBTable, type):
...
result = myDBTable(type=type, ...)
...
---------------

But obviously, the type=type part is wrong. Does anyone know how to fix
this?


Thanks so much,

Frank

Timur Izhbulatov

unread,
Dec 10, 2006, 2:18:20 AM12/10/06
to turbo...@googlegroups.com

def commonFunction(myDBTable, **kwargs):
# ...
result = myDBTable(**kwargs)
# ...

--
Timur Izhbulatov
OILspace, 26 Leninskaya sloboda, bld. 2, 2nd floor, 115280 Moscow, Russia
P:+7 495 105 7245 + ext.205 F:+7 495 105 7246 E:TimurIz...@oilspace.com
Building Successful Supply Chains - One Solution At A Time.
www.oilspace.com

chiangf

unread,
Dec 10, 2006, 9:30:09 AM12/10/06
to TurboGears
Perfect, thanks!

Reply all
Reply to author
Forward
0 new messages