Testing for presence of arguments

Madhusudan Singh spammers-go-here at spam.invalid
Wed Aug 17 12:07:00 EDT 2005


Diez B. Roggisch wrote:

> I don't have the details ready - but in the ASPN cookbook are recipes
> to e.g. figure insied a function f out how many results the caller of f
> expects - and act accordingly. This boils down to inspect the
> call-stack. So it ceratinly is possible.
> 
> However, I'd say it is almost 100% a design flaw. Or can you give us a
> compelling reason why you need this behaviour?
> 
> Diez

I am writing some code for a measurement application (would have used
fortran 95 if a library had been available for linux-gpib, but python is a
lot friendlier than C without the irritating and utterly pointless braces)
where one of the input parameters for the GPIB command is optional, and
depending on whether it is specified at all, an entire sequence of commands
has to be sent to the GPIB bus plus some input parameters recalculated.
Further, the sequence of commands depends on the range of values of the
optional parameter. And some of these commands in turn have similar
optional arguments.

All in all, the above would have been a bunch of simple one-liners with a
simple if block if python had something like the fortran 95 present()
intrinsic, but I could not find it. Hence my query. Just because there is
no simple and direct way of doing something in a language does not mean
that the application that requires it has a design flaw.

Unrelated question, how does one call a fortran 95 subroutine from python ?
I need really high speed of execution for that call (needed for each
measurement point, and is used to calculate some parameters for the
excitation for the next measurement point) and a scripting language would
not cut it.



More information about the Python-list mailing list