[Qgis-developer] New Python console idea: Expanding the Python
console to handle DSLs for plugins eg CADTools
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Fri Jun 17 09:45:21 EDT 2011
On Fri, Jun 17, 2011 at 1:55 PM, Nathan Woodrow <madmanwoo at gmail.com> wrote:
> Function MyFunction(someStringVar) as String
> Return "Foo Bar " + someStringVar
> End Function
> And then in the SQL statement.
> UPDATE table SET column = MyFunction("Hello World") where column > 100
> This would call MyFunction() for each feature and call a update. However
> one shortfall of this is that you couldn't define functions in the
> interactive Mapbasic shell inside MapInfo, meaning that you had to write a
> custom script just to do the above.
Yes, but I think once you get beyond three-liners you are going to
want to save these things in a file anyway. In python you'd just stuck
them in a .py file and import them. I don't really see typing at the
console as a good place for doing program development to any great
amount.
> Like you said we should just have to find way to say "this is a python
> variable" and "this is part of the string to send to the DSL". You might
> be able to use something like %%variableName or %%functionName. The console
> would parse the string that goes to the DSL and build a dictionary with
> %%variableName = realPythonVariable and then sends the string and the
> dictionary to the DSL which at that point it's up it to worry about
> evaluating and replacing the values and functions.
> Thoughts?
Yup, if you restrict yourself to putting python variable values into
other languages then that's a possibility. Not sure how you'll be
evaluating python functions with SQL variable argument though? Are you
expecting to be able to do:
import math
SQL: select years,months from foo where years > %%math.sqrt(months)
- since that would mean getting SQL values (months) passed to Python...
Even simple replacement of python variables us going to be tricky
since python variables can evaluate to all sorts of things - are you
just going to use the 'str' representation?
A nice list of use cases would be interesting.
Of course if you are willing to develop this then you can do what you
want :) There doesn't seem to be a lot of interest from the devs...
B
More information about the Qgis-developer
mailing list