473,387 Members | 1,502 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.

functions and named keyword arguments

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

Jul 18 '05 #1
2 1523
> 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"})

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2

Diez B. Roggisch wrote:
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"})

Brilliant - that's exactly what I was looking for.... thanks.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
--
Regards,

Diez B. Roggisch


Jul 18 '05 #3

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

Similar topics

0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
1
by: Fuzzyman | last post by:
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...
16
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
7
by: Boris Ozegovic | last post by:
Hi, I'am still learning Python and while reading Django tutorial couldn't understand this part: class Poll(models.Model): question = models.CharField(maxlength=200) pub_date =...
6
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to ...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
23
by: raphfrk | last post by:
I am having an issue with malloc and gcc. Is there something wrong with my code or is this a compiler bug ? I am running this program: #include <stdio.h> #include <stdlib.h> typedef...
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...
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: 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
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.