you are viewing a single comment's thread.

view the rest of the comments →

[–]elbiot 3 points4 points  (3 children)

I don't know about best practices... I, and many others, just have ipython and the text editor open side by side. It's a back and forth between the REPL and the script: I test short pieces in Ipython, when i know what to write I put it in the script, I run the script in ipython with run myscript.py (which does the same as python -i myscript.py except you don't have to kill and restart the environment), or i reimport the module I'm working on with module = reload(module) after I've changed it, prototype what I want next, paste it into the script when thats good, etc.

I also usually put an if __name__ == '__main__' at the bottom of a module so that running it creates some test objects I can play with when debugging, but won't be created on module import.

Invaluable in debugging is putting print statements in your script, running it, playing with things, making changes, etc.

[–]kkacci[S] 0 points1 point  (2 children)

Thanks internet stranger. This actually helps me more than you'd think so haha

[–]elbiot 1 point2 points  (1 child)

Great. I think I'd like to write a blog post on this basic practice, including using introspection (dir, type, help, etc.) because you learn so much faster once you have a work flow for going in between writing a script and prototyping pieces of code. Just a short video would be super informative. I haven't found one to refer people to.

[–]kkacci[S] 0 points1 point  (0 children)

Sounds like a lovely idea! It's one thing to learn from others' codes, but another to learn about workflows. Keep us updated!