¿ªÔÆÌåÓý

Locked Re: Scripting, Jython and importing selfwritten functions - crash and burn


 

Hi Dave. I never thought of that. Thank for your advice.
One last?question (maybe).
The function file? JMRI loads that and keeps it in memory it seems. Changes made in that file will not show up in the main script. Is there a way to force the reload of the function file without having to close down JMRI itself?

DC

s?n. 24. nov. 2019 kl. 18:36 skrev Dave Sand <ds@...>:

Dag Cato,

I recommend that you keep your scripts in the user files location.? In Preferences >> File Locations, set the script path.? This way JMRI upgrades don't affect your custom scripts.

Dave Sand



----- Original message -----
From: "Dag Cato Sk?rvik" <dag.cato.skarvik@...>
Subject: Re: [jmriusers] Scripting, Jython and importing selfwritten functions - crash and burn
Date: Sunday, November 24, 2019 11:25 AM

Hi Dave.? Thanks for you help. It wasn't the dash that was the original problem. (There where no dash in the original file) But you did point me in the right direction. After changing the filename I tried again without help.
Then I decided I would run the main script from the panels/run script command. When the dialogbox opened I saw that it was pointing to the jython-directory. I stored my files in another directory. So when I moved to function file to the jython directory it worked :-)

Dag Cato

s?n. 24. nov. 2019 kl. 17:50 skrev Dave Sand <ds@...>:

Dag Cato,

The problem appears to be the dash in the "my-functions" name.? The underscore character works.

Dave Sand



----- Original message -----
From: "Dag Cato Sk?rvik" <dag.cato.skarvik@...>
Subject: [jmriusers] Scripting, Jython and importing selfwritten functions - crash and burn
Date: Sunday, November 24, 2019 6:14 AM

Hello guys,
behind this heading lies nothing more than the wish two write functions in jython, saving them in a separate file and calling them from the main script.

Why? Just to try to keep the code more manageable.

I am no programmer at all. Learnt a little bit of Pascal and C/C++ in my youth.
My computer is a Elitebook bought on a fleamarket many years ago.
Java version is 11.0.5 64-bit
Windows 10 Version 1903 for x64 (KB4522741)
JMRI 4.17.3
Loconet simulator

Python has a import function.
If I hava a function test in a file called my-functions.py
I hoped that I was able to import?the function with this code

import my-functions
my-functions.test()

I doesn't work. Nothing happenes.
Well the latter is not quite the truth :-)

When i run the code with the Message Log window open?the whole JMRI crashes. I even have to go kill Java manually to start JMRI again. Without the Log Window opened I can just continue, everything is just fine.

But my question is about the import function. Can I use it in jython or do I have to live with having the functions in the main script?

MVH
Dag Cato







Join [email protected] to automatically receive all group messages.