Function that knows the names of its actual parameters

Aahz Maruch aahz at netcom.com
Mon Jun 19 19:32:00 EDT 2000


In article <394e45c3.513888 at news.btx.dtag.de>,
Stefan Franke <spamfranke at bigfoot.de> wrote:
>On 18 Jun 2000 21:53:57 GMT, aahz at netcom.com (Aahz Maruch) wrote:
>>
>>Why not simply write a function that takes a dict as its parameter?
>>
>>Maybe if you gave a better description of an occasion you think you need
>>this feature we could give you a better answer.
>
>Sure - see snippet below. Being able to call SQL_update without doubling
>the arguments would be nice. 
>If we could pass more than one of these dicts to SQL_update(), it would even 
>be possible to specify the WHERE clause with current parameters as well.
>I'm enclosing the magic arguments here into $...$ for provocative
>reasons <wink>:
>
>>>> index=1
>>>> member_name='you'
>>>> is_current=1
>>>> key=23
>>>> SQL_update(table, $member_index, member_name$, $key, is_current$)
>UPDATE my_table SET index=1, member_name='you' WHERE key=23 AND is_current=1

I'm assuming "$member_index" above should have been "$index".  I guess
what I'd do is something like this:

sqlDict = {
  'table': 'my_table',
  'updateClause': {
    'index': 1,
    'member_name': 'you'
    },
  'whereClause': {
    'is_current': 1,
    'key': 23
    }
  }
SQL_update(sqlDict)

IME, any time there's a direct mapping between variables and SQL, you
wouldn't want to do the magic trick anyway; any time you want to really
parameterize your SQL, you'd already have most of the info in a list or
dict in the first place (or *should*, if you wrote the code correctly).

--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"The only problem with Microsoft is they just have no taste." --Steve Jobs
(From _Triumph of the Nerds_ PBS special)



More information about the Python-list mailing list