functions and named keyword arguments

F

Fuzzyman

Sorry if this is a duplicate - I use the google interface and sometiems
it screws up (not showing stuff you've posted *or* not posting it).
Before you ask it's because at work I have no NNTP and *heavily*
restricted http.

A colleague and I have built a Validator object for use with ConfigObj
and other general schema situations. A config file is used to store a
schema that specifies how to test a value that it is valid.

keyword=function(param1, param2)

e.g. you could specify :
size = range(30, 50)

This means that the keyword 'size' must be an integer between 30 and
50. There is a matching function stored in a dictionary that is called
and the relavant arguments passed to it.

The function name and parameters are parsed from the config file that
defines the schema.

args, fname = parsefunction('range(30,50)')
test = funcdict[fname](*args)

What I can't easily see is any way of passing named keyword arguments
to the function. Suppose we wanted to pass keyword=param to a function
- is there any way of doing this ... obviously passing in
'keyword=param' as text has entirely the wrong result......

Anyone got any clues ? I suspect compiling the function into a code
object will help.... but this is a slightly black art for me.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
 
D

Diez B. Roggisch

Sorry if this is a duplicate - I use the google interface and sometiems
it screws up (not showing stuff you've posted *or* not posting it).
Before you ask it's because at work I have no NNTP and *heavily*
restricted http.

It is - so I requote my answer :)


Im not sure if I understand you fully, but if what you are after is how to
pass named parameters analog to positional args, do it as dict:

def foo(name=None):
    print name

foo(**{name: "Fuzzy"})
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top