Python like BASIC?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Post Reply
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Python like BASIC?

Post by Oziphantom »

Is there a tool that lets you use Python like basic?

Basically I want a buffer that I can type python into and then run it, to make some byte statements, or convert some string data to something else. Small simple little scripts. I don't want to have to make a file, set up the env, and then run it, when I'm done, delete the file etc.
Using the interactive mode is annoying as if you make a If statement then and you make a mistake on the 4th line after the if, you have to type the whole if again.

So even if it just has a "list" command so I can modify things, that would be better.

I've looked at Jupyter and it seems to have a better interactive mode, but still seems to have the same flaw.
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Python like BASIC?

Post by FrankenGraphics »

Sounds like you could maybe do those things in microsofts’ PowerShell? I realize you asked how to interface with Python differently specifically.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Python like BASIC?

Post by thefox »

Not aware of a ready-made solution for this. What I would do:

- Make a script for opening your editor of choice with a temporary file (could be something as simple as vim `mktemp` in Bash on *nix/WSL).
- Set up the editor so that you can easily run the file in Python.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Python like BASIC?

Post by rainwarrior »

Python comes with an application called IDLE, which will let you open a "python shell" where you can type and execute commands and see their results.
https://docs.python.org/3/library/idle.html

You could also use their web shell:
https://www.python.org/shell/

...or am misinterpreting your goal?
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: Python like BASIC?

Post by FrankenGraphics »

I think the problem is that IDLE executes either a line directly, or that (i think) you can't go back and edit lines waiting to be run, or you can't reverse-playback the interpreter, depending on how you look at the problem. Unless i'm missing something.
If you've buffered the variables (or files) you're manipulating, you can always redo if you mistyped something, though.

I suppose this is different from running BASIC on c64 or some such, where you interface directly with everything and can shift between line-for-line execution or hold until the user wants to execute. Also opposed to software like Qbasic which i'm more familiar with, which confused me at first when reading the OP.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Python like BASIC?

Post by rainwarrior »

Well with IDLE it's easy to go back and forth between shell and a program, i.e. running a program with F5 runs it in the shell and then leaves you sitting in the shell after it runs.

So, I often do quick test work to sketch out an idea in the shell, then copy it over to to the program editor when it gets a little more fully formed. That sort of makes a "rewind point" where I can just hit F5 and it will restart the shell but with everything that's in the program editor already applied.

I find a combination of shell with a program full of useful functions to be pretty great for exploratory work. An interactive way to run any of your functions with whatever parameter comes to mind, etc.

As far as undoing changes directly in the shell... aside from "import" you can re-assign any variables, or re-define any existing function, so a lot of actions are reversible (mostly).

I think it takes some experience to learn what kind of code design patterns work well with this approach, but I find this stuff pretty handy on a very regular basis.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Python like BASIC?

Post by tepples »

The problem with IDLE then is "Source Must Be Saved".
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Python like BASIC?

Post by rainwarrior »

Oh, now I understand, the problem is how the shell treats nested statements. Yes, that's pretty annoying, and I'm not aware of an alternative shell that makes that better. But like I said, I use it with an accompanying code file, which kinda solves that problem by giving you a mix of immediate and more editable code, but yes it has to be saved somewhere.
adam_smasher
Posts: 271
Joined: Sun Mar 27, 2011 10:49 am
Location: Victoria, BC

Re: Python like BASIC?

Post by adam_smasher »

Maybe look at trying some kind of ipython & emacs integration? You'd be able to edit your python code in a buffer and then send it over to the interpreter when ready, I imagine.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: Python like BASIC?

Post by Oziphantom »

Turns out FrankenGraphics has found a use for powershell ise;)
If one use the ISE (powershell_ise.exe) that ships with it, you can put some code into the "untitled" buffer up the top and then when you run it will just copy and paste it into the shell below and executes it. The syntax is slightly inconvenient in that one has to do

Code: Select all

$script="for i in range(0,10):
    print( str(i)+' squared is '+str(i*i))
     "

python -c $script
which means any " have to be escaped, but pythons I don't care about ' or " make this mostly not an issue ;)

However when you want to do something that is a loop and then have a bunch of ifs under it, you don't need to retype it in full each time ( or up arrow in reverse order each time )

Thanks FrankenGraphics
Post Reply