Fork me on GitHub

Thanks @david043, I'm very interested in this topic right now, especially interactive programming in Python. I'm trying to reproduce in Python one aspect of my Clojure workflow, which the Clojure website describes as, and which I would describe as "modify your program while debugging it", a combination of closely interwoven local experiments and global re-definitions. How far along are you along that goal? There seems to be some fundamental difficulties, in particular because global re-definition don't automatically propagate to dependent modules.

gratitude 1

More generally, has anyone else achieved a decent interactive workflow in Python?


I should maybe say "a decent interactive workflow in situated Python programs"

David Vujic07:06:11

I think the REPL driven thing works well in Python - not as well as in Clojure, of course. But very useful during development. What I do is starting up my editor with any required env-variables required to run the app. An example would be running against a dev-account in AWS and then I start the editor in an aws-vault context. I did that also when developing Clojure. I have set up my editor to use IPython as the in-editor shell instead of the regular python shell. With IPython, it is possible to configure it to auto-reload any module that has been changed. This makes it possible to develop, evaluate code in the REPL and keep it updated if changing any module that is used. It is the autoreload config of IPython.


That bit about IPython's auto-reload is interesting, thanks. I was going for this:

David Vujic07:06:40

Looks like a good option, too!

David Vujic07:06:13

I wrote a post a while ago about IPython and editor here:

👌 1
David Vujic07:06:59

Since then, I have quickly verified that it seems to work in VS Code too - using the “Python interactive …something” plugin. It was auto-suggested when I opened a python project.


Really appreciating this discussion; I’m doing some work on an existing Python codebase for the first time in years, and trying to figure out how to approximate the true REPL workflow as closely as possible (I know you just heard me say that, Val 😆). Are either of you emacs-centric? If so I’d be curious to hear what packages you’re using for Python. One thing I’ve been experimenting with is using global variables in the Python shell to try to approximate in Clojure. It seems to work ok if you can stick to being in a single module, but fail badly if you’re changing modules. The lack (as far as I can see?) of being able to put the Python shell into the context of different modules really gets in the way here…

👍 1
David Vujic19:06:36

I develop Python using emacs 😄 I use elpy and a couple of globally or venv-installed packages like isort, black, mypy and flake8. To be able to use the REPL in a good way I went for IPython with config to autoreload changed modules. Here’s some more info about my emacs setup:


Awesome, thanks! I tried to tell from the blog post you linked above, but the gifs are too small to tell what’s actually going on in them.

David Vujic19:06:57

😄 Yes, totally agree about the gifs! Since then I’ve learned that blog images should be bigger and possible to click to view a bigger version.


Still very useful, and appreciated!

gratitude-thank-you 1
David Vujic07:06:20

What I haven’t set up is a running program to connect a REPL to as we do in Clojure. But the program is “sort of” running once I load it into the REPL. 😄


I typically do that with debugpy. I find it very valuable to "project" the REPL into a function of interest with loaded locals and real-world state.

David Vujic07:06:06

cool, gotta check that out. Thank you!