473,569 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=functio n(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 1534
> 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
2331
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 Methods Version: $Revision: 1.34 $ Last-Modified: $Date: 2004/09/03 09:32:50 $ Author: Kevin D. Smith, Jim Jewett, Skip Montanaro, Anthony Baxter
1
1767
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 valid. keyword=function(param1, param2) e.g. you could specify : size = range(30, 50) This means that the keyword 'size' must be an integer...
16
2305
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 beginning to get out of hands if I continue to put in extra functionality in the (file-writing) output-functions....
3
2759
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? http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Defining_Functions doesn't actually give any insight.
7
1504
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 = models.DateTimeField('date published') # Django provides a rich database lookup API that's entirely driven by # keyword arguments.
6
3200
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 declare a pointer to them:
14
5989
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 static inside functions (i.e. local static objects) 5. objects declared at file scope.
23
2701
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 struct pxl { double lon, lat;
10
5100
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 not when I use a "normal" function: return len(object)
0
7700
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.