Thursday, 12 February 2015

A small IronPython console improvement

I wasn't going to put out a new release of MapGuide Maestro without crossing at least this item off my list. So after several weeks of coder's block about how to solve this particular problem, I finally cracked it.

So I proudly present: Support for capturing user input from stdin in the IronPython console!

And yes, you can store the result as variables

You can also use input() for capturing user input from stdin, but it has the caveat of auto-evaluating whatever you enter as a Python expression. What this means is that if the user tried the same thing as above with input(), it will fail.

This is because the input of Jackie Ng is not a string literal, which causes Python to throw the SyntaxError. With input() if you are capturing strings, you have to quote them.

The real power of input() is allowing you to input raw python expressions, like capturing an array as input.

If you just want to capture string input, follow the advice of the Python documentation and use raw_input() instead.

The code to get this working doesn't look pretty IMO, but that's better than what we had before, which was nothing! So here's to more flexible python scripts in the next release of Maestro.

As for that next release, still some more pending items to tick off first.