Testing for presence of arguments

Diez B. Roggisch deets at web.de
Wed Aug 17 13:51:10 EDT 2005


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

I still don't see why default arguments like None won't do the trick.
If The argument _can_
be some value (let's say an int) or None, you still could go for a
default value like () or any other value
from a different domain.

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

Certainly, but as certainly thinking in terms of one language while
using another is prone to
creating design flaws.

So far you still haven't convinced me that default arguments don't work
for you. To me it seems that
your idiom of present() is modeld by python's

if arg is None:
    whatever

pretty mich. It might help if you show'd us what your code would like
_if_ python
had present() available. Then we can see what alternatives there are.

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

Didn't ever try that, but either do it in C, or if fortran code can be
exposed as C lib, use that (ctypes is your friend). I'm not aware of a
fortran binding - but I never tried to find one. Basically Python can
interface with everything that can behave like C - which is the least
common denominator I think, so there should be some way.

Regards,

Diez




More information about the Python-list mailing list