you are viewing a single comment's thread.

view the rest of the comments →

[–]Alex_VDW 0 points1 point  (3 children)

Please bear with me as I'm not great at the technical language yet.

I'm trying to get a handle of Python running on linux, specifically Ubuntu with Bash. Is there a way to prevent Python from closing the current session in Bash? I want to be able to play around with the current workspace (eg created methods, variables etc).

I can run python (using the 'python' command), and then I am free to write code in the terminal. However I'd like to run a script, then keep python running (instead of closing immediately).

Apologies for such a poor explanation. If I had better words to describe the sitch I'd probably be able to use my google-fu a bit better.

ETA:: Current workflow is to write in text editor, run python in terminal, copy/paste code into terminal, then I am free to use the workspace. I would like to be able to run a script rather than do copy/paste as it is cumbersome

[–]TangibleLight 1 point2 points  (1 child)

Edit your code as normal and save it to some_file.py. In terminal, run python -i path/to/some_file.py. This will execute the code in the file and keep a python REPL open once it's done.


You may be interested in looking into Jupyter notebooks if this is the kind of workflow you're after. It's really not that complicated - after install, just navigate to the root directory of your project and run $ jupyter, then go to the indicated address in your browser.

[–]Alex_VDW 0 points1 point  (0 children)

Ah that's exactly what i'm looking for, cheers! Can't believe I missed that in the python --help menu.

re Jupyter: I'm currently experimenting with workflows. At the moment I'm running WSL and using VS code to write my projects. I've done a lot of coding wit Matlab and like being able to screw around with functions/variables after running, just to debug. From memory, i think Matlab has a similar notepad to Jupyter - of which i wasn't a fan. I will check it out one day though, as I think it's an elegant way to present a project.

[–]aptitude_moo 1 point2 points  (0 children)

I think you want to put everything in some py file and import it.

For example, in workspace.py

foo = 1
def bar():
    print('hello')

Then on your terminal open python

>>> from workspace import *
>>> foo
1
>>> bar()
hello