473,387 Members | 1,760 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,387 software developers and data experts.

Keyword Named Args

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 relevant 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

Jul 18 '05 #1
1 1756
> 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......


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"})
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2

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

Similar topics

6
by: Roy Smith | last post by:
I've got a function that takes a couple of optional keyword arguments. I want to check to make sure I didn't get passed an argument I didn't expect. Right now I'm doing: conversion = None drop...
3
by: black | last post by:
Hi all~ I met problem when trying passing keyword arguments to derived class. my goal is to pass all keyword arguments to taht derived class as they did for superclass, but the result was not...
1
by: svilen | last post by:
hi. this was named but it is misleading. i want to have the order of setting items in intrinsic dicts (keyword args, or class attributes, etc). which is, a prdered dict trhat matches the...
14
by: Edward Diener | last post by:
In the tutorial on functions there are sections on default arguments and keyword arguments, yet I don't see the syntactic difference between them. For default arguments the tutorial shows: def...
3
by: Steven Bethard | last post by:
I mentioned in a previous post that I'd much prefer some sort of keyword as a decorator indication than a character like @ (or the recently suggested |). A promising note on python-dev: ...
2
by: Fuzzyman | last post by:
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...
10
by: David Murmann | last post by:
Hi all! I could not find out whether this has been proposed before (there are too many discussion on join as a sequence method with different semantics). So, i propose a generalized .join method...
10
by: Armando Serrano Lombillo | last post by:
Why does Python give an error when I try to do this: Traceback (most recent call last): File "<pyshell#40>", line 1, in <module> len(object=) TypeError: len() takes no keyword arguments but...
3
by: Sean DiZazzo | last post by:
Why is the following not working? Is there any way to get keyword arguments working with exposed XMLRPC functions? ~~~~~~~~~~~~~~~~ server.py import SocketServer from SimpleXMLRPCServer import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.