These are good news! After writing the previous e-mail, I looked on how keyword arguments could be processed by the C++ code of the _meep.so module backend. This would be probably another way to go. (http://docs.python.org/extending/extending.html#keyword-parameters-for-extension-functions) However, I have no experience with SWIG and I cannot decide which way would be the most clean and effective.
If the python-meep module is improved this way, it would be also useful to update the documentation to use the shorter function calls. Filip On Mon, 13 Feb 2012 14:05:31 +0100 Martin Fiers <[email protected]> wrote: > Dear Dominec, > > I am sure this is possible. I use SWIG and I can pass my arguments to > the python-interface using this (I define it right after the %module): > > %feature("kwargs"); > > By using this feature, C++ function parameter names automatically > become the argument name accessible in Python. > I can get this in the signature (e.g. in an ODE solver I wrote): > > def solve_for_dt_src(self, *args, **kwargs): > """solve(self, npy_cdouble src, double t, double dt)""" <---- > this is due to autodoc (read further on) > return _solvers.something_solve_for_dt_src(self, *args, **kwargs) > > It will check whether the kwargs are correct. So writing > >>> solve(dtt=0.3) > will fail because it doesn't recognize dtt. > > In addition, using autodoc can be useful (see > http://www.swig.org/Doc1.3/Python.html#Python_nn69): > %feature("autodoc", "1"); > > I hope this helps, > > Regards, > Martin Fiers > > 2012/2/13 Filip Dominec <[email protected]>: > > Hi, > > I am learning to simulate electrodynamics in python-meep. I observed that > > very often people define a variable and then they pass its value to a > > function so that they know what each parameter means. > > > > Although this is surely better than just providing unnamed numbers, the > > correct pythonic way is AFAIK to use parameter names even for non-keyword > > parameters, e. g. > > > >>>> def a(x,y): return x**y > >>>> a(10,2) > > 100 > >>>> a(y=2, x=10) > > 100 > > > > If python-meep programs could be written with all parameters named, it > > would increase readability a lot. (I can see that the meep module passes > > the argument as dictionary to the compiled backend, which is somehow > > processed by SWIG, so this may not be possible at all.) Do you think this > > this can be done? > > > > Filip > > > > _______________________________________________ > > meep-discuss mailing list > > [email protected] > > http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss _______________________________________________ meep-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

