It is currently Fri Sep 21, 2018 12:33 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Python like BASIC?
PostPosted: Mon Apr 23, 2018 2:20 am 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 579
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.


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 3:35 am 
Offline
Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 1778
Location: Gothenburg, Sweden
Sounds like you could maybe do those things in microsofts’ PowerShell? I realize you asked how to interface with Python differently specifically.

_________________
http://www.frankengraphics.com - personal NES blog


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 10:22 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 3127
Location: Tampere, Finland
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


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 10:44 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6809
Location: Canada
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?


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 11:04 am 
Offline
Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 1778
Location: Gothenburg, Sweden
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.

_________________
http://www.frankengraphics.com - personal NES blog


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 11:24 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6809
Location: Canada
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.


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 11:30 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20562
Location: NE Indiana, USA (NTSC)
The problem with IDLE then is "Source Must Be Saved".


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 11:41 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6809
Location: Canada
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.


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Mon Apr 23, 2018 1:18 pm 
Offline

Joined: Sun Mar 27, 2011 10:49 am
Posts: 265
Location: Seattle
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.


Top
 Profile  
 
 Post subject: Re: Python like BASIC?
PostPosted: Tue Apr 24, 2018 1:33 am 
Offline

Joined: Tue Feb 07, 2017 2:03 am
Posts: 579
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group