Calling all Python programmers...

Anything relating to non Sinclair computers from the 1980's, 90's or even before.
Post Reply
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Calling all Python programmers...

Post by TMD2003 »

I know very, very little Python and a potentially useful program has left me stumped.

I'm tackling Dragon 32 programming - which I do know something about, seeing as my brother had one back in the day and I made a few programs on it when he was out with his mountain bike.

This handy utility supposedly converts between the .CAS format used for Dragon 32 tapes and the raw text .BAS format. It will also convert the other way, apparently, and this will be useful to me.

I've saved a very simple program as TEST.BAS:
10 PRINT "TEST"
20 GOTO 10
(yes, we all did this on a ZX81 back in the day)

It should be executed with:
python bas2cas.py test.bas test.cas

No matter what I do, whichever way round I put the .cas and .bas files (it's certainly the other way round for CAS2BAS), no matter if I put the -h and -b switches in or not for a custom header and base (no idea why I would need to do that), I get the same error:

Code: Select all

- line 55
self.report(1, f"Located program {filename}")
                                           ^
SyntaxError: invalid syntax
...what could possibly be wrong with that closing quote?

The "f" is something to do with a function later in the code (it says f.write(output_data) for instance), so that can't be causing the error.

It's what I would imagine to be a very short, simple block of code for an experienced programmer. It's a complete mystery to me why what is apparently perfect syntax is causing an error, and surely if it's been released on GitHub it should work, otherwise others would report to the programmer with "here's a bug and this is what it's doing and here's all the data you'd need to fix it", whereas all I can say is "it doesn't work, this is what it says, why doesn't it work?"

It is at times like this I realise that I am not, and never will be, a programmer. At least, not outside our own little happy colour-clashing world. So no "HERP DERP GIT GUD SCRUB" business. I have four days to do what I need to do, not four years to learn Python programming.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
EdToo
Manic Miner
Posts: 228
Joined: Thu Nov 03, 2022 4:23 pm

Re: Calling all Python programmers...

Post by EdToo »

I've just installed python on my laptop and downloaded this.

Using a windows machine I wrote the same basic file as you in notepad.

I then saved it as test.bas and using powershell ran python bas2cas.py f:\test.bas f:\test.cas. This did nothing except redisplay the input options for bas2cas.py. (F:\ is my usb stick).

I then ran the same command but with an extra option on the end python bas2cas.py f:\test.bas f:\test.cas -dd and that generated a test.cas file on f:\ drive.

I don't have anything to test is the cas file is valid, but the python script appears to work for me.
EdToo
Manic Miner
Posts: 228
Joined: Thu Nov 03, 2022 4:23 pm

Re: Calling all Python programmers...

Post by EdToo »

I've just installed XRoar which was interesting as I never came across the Dragon before. I then installed the correct ROM, inserted the test.cas file, typed CLOAD "" followed by LIST and got the program showing on screen, so it looks like the python works, but you need to add the optional switches.
Image
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Calling all Python programmers...

Post by TMD2003 »

Interesting. The -dd switch is to get DragonDOS commands tokenised, and I won't need those. Did you try it without?

Maybe the problem is that I need the full path in the filename, which I never did.

It does show me I'll need to pay attention to capital letters - the Dragon doesn't have any, and those inverse-video characters are what it uses instead; they'll only show up as lower case on a printer. The program should not run with those inverse characters in the listing.

Anyway, this gives me a lead.

I checked which version of Python I'm running - it's 3.4.4, and from what I can see in the introductory text, it needs 3.4.0 at least, so that shouldn't be a problem. Right, more tests coming up...

EDIT: ...no change, with the full path to the filename I'm still getting the same syntax error. Using the -dd switch or not, using the -h and -b as well, both, neither, nothing bypasses the syntax error.

EDIT EDIT: I'm trying to update Python as far as I can - and 3.8 is the most I can do with Windows 7. I don't get the option of an installation package, just a GZIP tarball that assumes (1) I'm on some kind of Unix system, and (2) I have to install it manually, the way a programmer would do. Looks like I'm stuck with 3.4.4 for now, or until I take some kind of lengthy programming course.

This is getting extremely frustrating. Why would this program work for @EdToo straight out the box but not for me?
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
PeterJ
Site Admin
Posts: 6901
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Calling all Python programmers...

Post by PeterJ »

@TMD2003,

It's not mentioned in that repository if the code is Python 2 or 3. Unfortunately code written in V2 isn't compatible with v3 and vice versa.

It may have nothing to do with it, but it may be useful if you do any more Python.

When you installed Python did you tick the option to update Windows paths?
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Calling all Python programmers...

Post by TMD2003 »

PeterJ wrote: Wed Dec 21, 2022 12:51 pm @TMD2003,
It's not mentioned in that repository if the code is Python 2 or 3. Unfortunately code written in V2 isn't compatible with v3 and vice versa.
It may have nothing to do with it, but it may be useful if you do any more Python.
requirements.txt says:

pytest==6.2.1
pytest-mock==3.4.0

That's where I get the impression that it should be v3.4 that's required, and that's what I have.

I've now tried transferring the entire BAS2CAS folder onto a USB stick, so that there are no folders with spaces in the name to get in the way, I'm running the code from there, I've tried combinations of the -cc and -dd switches (the -cc might cause even more problems...), I've tried the full filename, I've tried it without the path, nothing will work. It always gives the same syntax error, always points at the same closing quote. The problem is in the code, which for some unfathomable reason, @EdToo doesn't have. It isn't executing the line that finds the input filename in the first place.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
PQR
Manic Miner
Posts: 242
Joined: Sat May 12, 2018 11:35 am
Contact:

Re: Calling all Python programmers...

Post by PQR »

Code: Select all

self.report(1, f"Located program {filename}")
This line is using a so called f-string. These were first introduced in Python 3.6.
So that is why you are getting a syntax error with Python 3.4.

You can change the line in question to:

Code: Select all

self.report(1, "Located program {}".format(filename))
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Calling all Python programmers...

Post by TMD2003 »

PQR wrote: Wed Dec 21, 2022 1:05 pm

Code: Select all

self.report(1, f"Located program {filename}")
This line is using a so called f-string. These were first introduced in Python 3.6.
So that is why you are getting a syntax error with Python 3.4
Mystery number one solved.

Mystery number two: how to upgrade to 3.8...
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
PQR
Manic Miner
Posts: 242
Joined: Sat May 12, 2018 11:35 am
Contact:

Re: Calling all Python programmers...

Post by PQR »

See my edited post above for a quick fix.
EdToo
Manic Miner
Posts: 228
Joined: Thu Nov 03, 2022 4:23 pm

Re: Calling all Python programmers...

Post by EdToo »

On the page you linked to in the original post on the righthand side is link to the release

https://github.com/jimbro1000/cas2bas/r ... tag/V2.0.0

On this page there is an option to download tar.gz or zip. I chose the zip option as I'm on a windows machine. I extracted this file then from windows explorer held down shift over the folder I extracted into and chose open a powershell here (on windows ten older machine should say open a command shell here or something similar). Then in powershell ran the command mentioned above.

I've just tried again and I have to use the extra options. Despite the program saying this isn't necessary.

You were quite right about the lowercase letters in my listing. The program wouldn't run. I've just tried using all uppercase and it loads and runs just fine.

The site does say the python version shouldn't matter too much.
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Calling all Python programmers...

Post by TMD2003 »

Panic over! No more mysteries. I've found an installer for Python 3.8.10.

The upshot of this is that I can choose "python" to run 3.4.4 or "py" to run 3.8.10...

And I have a .CAS file! I've used the -h and -b switches to make it so that there's no attempt to use DragonDOS commands that aren't there (DLOAD/DSAVE and such, there are probably a lot of others).

Now let's make this Welsh computer roar... in an American accent. Dude, like... bore da, yo.

EDIT: final mystery solved, the one with the switches. When I was wondering "what's this F -H on the screen?" when it loads, I found it's asking for a filename immediately after the output file.

Hence:

Code: Select all

py bas2cas.py in.bas out.cas BOB
will create a tape with a filename that displays as BOB when it loads.

*cracks knuckles*

Here goes... something.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
User avatar
PQR
Manic Miner
Posts: 242
Joined: Sat May 12, 2018 11:35 am
Contact:

Re: Calling all Python programmers...

Post by PQR »

Good to hear you found a proper installer of Python 3.8.

It's not uncommon to have multiple versions of Python installed.
On my Mac I have several aliases that point to particular versions:
python --> Python v2.7.10
python2 --> Python v2.7.10
python2.6 --> Python v2.6.9
python2.7 --> Python v2.7.10
python3 --> Python v3.8
User avatar
TMD2003
Rick Dangerous
Posts: 2047
Joined: Fri Apr 10, 2020 9:23 am
Location: Airstrip One
Contact:

Re: Calling all Python programmers...

Post by TMD2003 »

Cheers to everyone who helped on this one. For those who don't already know, the Dragon 32 has an utterly revolting editing system - it'll make you pine for the ZX81's editor with a line that fills the screen - and trying to write what I'm writing directly on XRoar means I'd be progressing at about a tenth of the rate that I am. It's a massive advantage that I'm far better at Dragon BASIC than at "real-world programming that actually means something to a lot more people and might actually be useful and could even be profitable", at least in this very isolated instance - because if I was as bad at Dragon BASIC as real-world programming I'd have had to give up on this project as a bad job before it'd even started.

One day, I'll crack Python. One day, even it it takes until I'm older than Don Priestley. If anyone knows of any good books that actually have exercises that I can test myself with (as opposed to Zed Shaw's "spend about a week writing your own examples of this code", with no actual answers given), do tell me.
Spectribution: Dr. Jim's Sinclair computing pages.
Features my own programs, modified type-ins, RZXs, character sets & UDGs, and QL type-ins... so far!
Post Reply