Last weekend, I attended a two-day Python bootcamp put on by the Penn Institute for Computational Science. I’ve been making incremental progress learning Python for almost a year now but haven’t needed to code very often, which makes it hard to pick up quickly. I’m finally reaching the point in my research where I actually need to write and modify code to analyze my data (yay!), so I thought attending a (free) Python bootcamp would be a perfect way to help me work out some of the kinks and confusion I’ve faced from trying to teach myself to code. I wasn’t sure what to expect, but when I arrived, I found a room full of ~40 grad students and post-docs from all kinds of backgrounds. There was a group of bioengineering PhD students, including me, but there were also people from linguistics and mechanical engineering and the school of medicine. Our instructor was a former Penn grad student and post-doc who now works in industry but is passionate about teaching people how to use Python well (here's a link to his website). The bootcamp moved at a great pace for me and I found the overall experience to be a great way to solidify my coding skills.
I know everyone’s experiences learning to code or learning a new coding language are unique, and people run into different challenges depending on their background. I’d like to share with you one of my biggest challenges in learning Python so far and two solutions I came across during the coding bootcamp.
Challenge: Python is run through the terminal. Once you’ve run the script, all the variables are wiped away and it can be really challenging to troubleshoot.
This was particularly challenging for me because my first intro to Python was through running long, involved scripts that someone else wrote and trying to modify it to suit my needs. I ran the script over and over again with slight modifications and a ton of print statements to try to figure out what on earth was going on.
Solution 1: Spyder
You can pull up your current working directory, the script you are editing, and a python ‘Console’ all in the same workspace. Once you want to run the script, you save it and hit the green arrow (similar to Matlab). The part that gets me excited is that the variables aren’t wiped away after the script is done, so you can type any of the variables defined in the script into the console and get information about them.
Solution 2: iPython (or Jupyter)
What are some of your biggest headaches in learning to code? Have you found any good solutions? Write about them in the comments!