[Tutor] How to pass varying number of arguments to functions called by a dictionary?

boB Stepp robertvstepp at gmail.com
Wed Feb 11 16:29:34 CET 2015


On Wed, Feb 11, 2015 at 8:45 AM, Dave Angel <davea at davea.name> wrote:
> On 02/11/2015 08:27 AM, boB Stepp wrote:
[...]
>
> Sure, it's viable, but the best approach depends on your goal (use case),
> and your restrictions.  Are these functions really totally unrelated to each
> other?  You not only don't have the same number of arguments, but the values
> don't even have anything in common?

The file/module containing functions extract information from another
software application (with its own scripting language) and ask that
software to perform certain calculations in its scripting language.
The dictionary keys are conventional symbols for types of calculations
that someone might request. I have a current set of requested
calculations, but this will likely be augmented with new ones in the
future. Depending on the request, there might be no arguments passed,
meaning there is a simple request for information from the software
application that requires only a look-up, or the actual software
application may have to do calculations requiring one or more passed
values. Which and how many values depends on the type of calculation
requested.

> There's an implied constraint that you're not permitted to change the
> functions.  Are you really constrained to only change the caller?

I think this is the case, but I am open to other ideas.

> Assuming that you seriously want to be able to do this, the only use case I
> can imagine are:
>    1) you're writing an interpreter

I was not thinking explicitly in this way, but in effect I am
translating requests in Python code into a proprietary scripting
language, and vice versa.

[...]

> In each case, there are probably better ways...

I am open to suggestions!

Thanks!


-- 
boB


More information about the Tutor mailing list