petite python problem
John Rickman (71) 646 posts |
This works for BASIC:-
But I get no output from this in Python
Can anyone cast a bit of light here? |
Stuart Painting (5389) 714 posts |
Is it perhaps important that the response to OS_Byte 0 is returned as an error block? |
Chris Mahoney (1684) 2165 posts |
You’re probably on the right track there! Python likely thinks that OS_Byte 0 has failed since it sets the V flag. |
Chris Johns (8262) 242 posts |
A little odd – i’d expected it to raise a swi.error exception like swi(“OS_ClI”,“s”,“FX 0”) does. I’ve only had a very quick look but can’t see why OS_Byte 0 doesn’t. |
Chris Johns (8262) 242 posts |
Think I’ve got it. swi.swi(“OS_Byte”,“ii”,0,0) is what you want. Otherwise R1 is undefined, and if it’s non-zero you’ll get the machine info returned instead. I think BASIC defaults unset regs to 0. |
John Rickman (71) 646 posts |
swi.swi(“OS_Byte”,“ii”,0,0) Thanks very much – I have spent the last hour trying different things to get it to work. |
John Rickman (71) 646 posts |
Here is another petty python puzzle for a idle moment on a Sunday afternoon.
This does not:-
Both methods work in BASIC
|
Andrew McCarthy (3688) 605 posts |
Here I see the following:
|
Doug Webb (190) 1180 posts |
I get the same as Andrew apart from:
|
John Rickman (71) 646 posts |
Curious – this is what I get …
I will investigate further as it seems to be aproblem with my install |
John Rickman (71) 646 posts |
I get the same error using python 3.10
Not sure what “application” means here. Is it the star command *echo, or OS_CLI? |
David Pitt (3386) 1248 posts |
Python 3.8.8+ (riscos-1, Feb 22 2021, 21:48:54) [GCC 4.7.4] on riscos Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.system('echo hello world') hello world 0 >>> import swi >>> swi.swi ('OS_CLI','s','echo hello world') hello world swi.error: SWI name not known >>> swi.swi("OS_CLI","s","echo hello world") hello world >>> Hmm! |
Andrew McCarthy (3688) 605 posts |
As you intend to check your installation, it’s probably worth mentioning an observation. I discovered two versions of the Python riscos_toolbox pip (0-1-0 and 0-2-0); the first version works with the toolbox demo program !tbxeg, and the second version doesn’t. I haven’t found a way to revert to the earlier version. |
John Rickman (71) 646 posts |
Hmm! Indeed! I have just tried with Python 27 with the same failure:
So it fails on 2.7, 3.8, and 3.10 – what the failures have in common is that they are all on the same machine. ARMX6. |
Doug Webb (190) 1180 posts |
I was testing on my ARMX6 5.29 (01-Feb-22) and did not get the error. |
John Rickman (71) 646 posts |
Doug I didn’t mean to suggest it was a generic ARMX6 problem but that the errors were happening on the same machine which hapens to be an ARMX6. |
Doug Webb (190) 1180 posts |
Thanks for the clarification John and it does indeed seem the plausable explanation though I’ve often found that keeping an open mind sometimes gets you out of the dead end you can end up in :-) |
John Rickman (71) 646 posts |
I discovered two versions of the Python riscos_toolbox pip (0-1-0 and 0-2-0); the first version works with the toolbox demo program !tbxeg, and the second version doesn’t. There is only one on my machine in !PythonSite.Python38.Site-Packages I haven’t found a way to revert to the earlier version. Have you tried uninstalling?
Note The toolbox is the same level as the PIP install. You would have to install with the right level ie perhaps
|
Andrew McCarthy (3688) 605 posts |
Thank you, John; I discovered the anomaly when creating a new Python install on another machine. Whilst I was moving between devices, I removed the riscos_toolbox 0-1-0 from the machine where the example had worked to validate my assumption that it was the newer version. I must admit I hadn’t considered not being able to revert to an earlier version then.
|
John Rickman (71) 646 posts |
I discovered two versions of the Python riscos_toolbox pip (0-1-0 and 0-2-0); the first version works with the toolbox demo program !tbxeg, and the second version doesn’t. Andrew, I have posted a response to your problem on another thread that deals specifically with !TbxTest and old versions. (Thread: Python38 issue) I am also working on instructions for getting !TbxTest to work as the original has some problems, and will post it there also. This thread is best used for simple puzzles. |