Keyboard Shortcuts
Likes
Search
Locked Jython script debugging in JMRI
The community is very helpful in providing example Jython scripts to do a variety of useful functions. Of course, all scripts need to be modified for local circumstances and that is where I start to have a problem. Is there any capability within JMRI to help me in debugging my scripts? I’m just learning Jython and it seems that every time I make a minor change, something breaks and the script just hangs. I’m using Notepad++ for editing and sometimes even find that my indentation gets changed when I load a script into the JMRI script entry window. ?Eventually, I trace these problems back to a misspelled variable or method name or a forgotten type conversion or some other equally “obvious” problem, but it sure would be helpful to have a tool for doing syntax (and perhaps some semantic) checking for JMRI scripts. ?I know there are dozens of tools out there, but is there a commonly used “simple” one, perhaps like there is In the Arduino IDE? ?Any suggestions would be appreciated.
?
Jerry? ___________________________________ jerryg2003@... |
Jerry, Better informed members will provide even more information, but for now a short list of sources for clues:
Cliff in Baja SoCal |
If you open a Script Output window _and_ have the Console window open (from Help menu), Jython should give somewhat-useful error messages in many cases. Some go to one, others to the other, so you need both.
macOS users have BBEdit and similar tools that do some syntax checking and assistance. I don’t know of similar smart editors for Window, but I’m sure they exist. Bob On Aug 20, 2018, at 8:46 AM, JerryG via Groups.Io <jerryg2003@...> wrote:-- Bob Jacobsen rgj1927@... |
NotePad++ works well with Windows and files with the ".py" extension in that it recognizes keywords and does an almost adequate job with indentation. Comparing different editors is beyond my intended purpose here. NotePad++ has a potential indentation problem with intermixing lines that start with tabs "\n\t" with lines that start with blanks "\n " and the JMRI Jython interpreter does not explain why it gets lost, only that the indentation is not correct. Once I realized the cause of this issue, I now always use tabs for indentation, even if this means modifying an otherwise correct sample script. It should also be noted that if one uses either the triple quote long string or the triple apostrophe long string for a comment, then the beginning line of that comment must be indented to be consistent with the lines before and after that beginning line. This too is much easier to identify with tabs rather than with spaces. Please don't ask how long it took me to figure this out. Several of the samples in the JMRI distribution jython folder files intermix blanks and tabs and blanks and execute well as-is, but often troubles occur if even a simple modification is made using NotePad++ and not paying attention to the inconsistency. There is an option for setting how many blanks you want the editor to translate as a tab when inserting a new line, but even that has not provided the consistency that JMRI wants to see. Cliff |
Thanks Cliff and Bob. ?I’ve been opening the script output window but will now also open the system console and look into logging. ?Cliff - you solved the indentation issue: ?I thought it was somehow related to tabs and spaces but couldn’t quite put my finger on it. ?Is this a “bug” in JMRI or just an unpleasant feature of the Jython interpreter?
thanks again, Jerry ___________________________________ jerryg2003@... |
Jerry,
toggle quoted message
Show quoted text
The tabs vs. spaces question can generate heated discussions. It has nothing to do with JMRI or Jython, it is a Python characteristic. The only rule is never mix tabs and spaces. I always use spaces since I don’t like to see the indents change based on the software that is displaying the program. Tabs tend to default to either 4 or 8 but can be anything. Dave Sand On Aug 20, 2018, at 9:32 PM, JerryG via Groups.Io <jerryg2003@...> wrote: |
It’s really a feature of Python/Jython community, which strongly believes that indenting with spaces (not tabs) is the right way to go:
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out. -- Georg Brandl See also PEP-8, the style guide for Python code () Of course, some people do prefer tabs, and should be able to use the tab key; a good way to handle that desire is to have your editor change “tab key” into the necessary number of spaces. (It also helps to have an editor that displays invisibles like tabs and spaces) People have occasionally gone through the JMRI-released script files to convert tabs to spaces. We should probably do that again… Bob On Aug 20, 2018, at 7:32 PM, JerryG via Groups.Io <jerryg2003@...> wrote:-- Bob Jacobsen rgj1927@... |