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.
Sounds like you could maybe do those things in microsofts’ PowerShell? I realize you asked how to interface with Python differently specifically.
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.
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.htmlYou could also use their web shell:
https://www.python.org/shell/...or am misinterpreting your goal?
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.
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.
The problem with IDLE then is "Source Must Be Saved".
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.
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.
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:
$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