JMRI: The Python/Jython language
Python is a widely used scripting language that's available on many types of computers. A Java-based varient, called Jython, has been integrated with JMRI to make it easy to control a model railroad from the command line of a computer. For our purposes, the two languages are completely the same.If like me you prefer to read off paper, there are lots of books available on Python. Perhaps one of the best for beginners is "Learning Python" published by O'Reilly. It contains more than you really need to know, though.
The jython.org site has some introductory information, though their tutorial spends too much time on the engineering details at the beginning. You might want to skip to the part about the language itself.
Non-programmers might want to start with some of the resources for them listed on the python website.
If you are interested in the underlying technicalities of the langugage, IBM Developerworks has two good articles here and here. They also have a nice tutorial here, although they require you to register with your email address to access it.
Looking at the examples in the "jython" directory in the JMRI distribution might also help.
Things somebody should point out to you
The single oddest thing about Python is that the indentation matters. Instead of using { and } characters to indicate the beginning and end of a block or function, that's done with indentation in Python. Of course, in a C-like language people usually indent blocks anyway, but it takes a little getting used to that you have to do it in Python.For example, this is a sytax error:
a = 15
print a
b = 21
because those statements, though logically grouped at the same level in the program,
aren't indented the same. This sounds like a pain at first, but you
rapidly get used to it. Then it makes things
like the following
pretty easy to read, without having to worry about where the { and
} go:
if ( now == -1 ) :
done = 1
else :
done = 0
print done
If you do get a message about "Syntax error", look at the indicated line
number to see if your indentation isn't lined up.