other-languages

val_waeselynck 2022-06-02T07:11:28.364999Z

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 https://clojure.org/about/dynamic, 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.

1
val_waeselynck 2022-06-02T07:11:56.686899Z

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

val_waeselynck 2022-06-02T07:18:03.867619Z

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

2022-06-02T07:19:11.971719Z

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.

eggsyntax 2022-06-13T19:06:09.592929Z

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 https://blog.michielborkent.nl/inline-def-debugging.html 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
2022-06-13T19:12:36.829919Z

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: https://github.com/DavidVujic/my-emacs-config#python

eggsyntax 2022-06-13T19:13:41.220149Z

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.

2022-06-13T19:15:57.863309Z

😄 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.

eggsyntax 2022-06-13T19:19:40.319209Z

Still very useful, and appreciated!

1
val_waeselynck 2022-06-02T07:21:58.835449Z

That bit about IPython's auto-reload is interesting, thanks. I was going for this: https://pypi.org/project/reloader/

2022-06-02T07:23:40.670259Z

Looks like a good option, too!

2022-06-02T07:24:13.249209Z

I wrote a post a while ago about IPython and editor here: https://davidvujic.blogspot.com/2021/09/can-we-have-that-in-python-too.html

👌 1
2022-06-02T07:24:59.079849Z

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.

2022-06-02T07:20:20.859479Z

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. 😄

val_waeselynck 2022-06-02T07:23:15.787779Z

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.

2022-06-02T07:27:06.531679Z

cool, gotta check that out. Thank you!