The first steps of learning a new programming language is often to reproduce code written by others in books and on webpages. Seems easy, right? Should work perfectly, right? Not always.
Three things to do if borrowed code doesn’t work for you:
- Always read the comments. Several times now, I’ve found that the original poster was almost right and a commenter with more experience than me had found the error or made the necessary addition.
- Know your versions. I’m learning Python and I’ve learned that there are two versions with different syntax. Knowing the version of your tutorial is important. Both books I’m using–Make: Getting Started with Raspberry Pi 2nd edition by Matt Richardson and Shawn Wallace and Hello World: Computer Programming for Kids and Other Beginners 1st edition by Warren and Carter Sande to explore python more in depth–use version 2.7 syntax.
- Retreat and reboot. I’m using IDLE as my text editor and python shell. I thought I had correctly installed pygame and I wasn’t getting syntax errors, but the pygame window refused to open. The code was right, and it just wouldn’t run. I closed everything out and went away for awhile. When I returned and fired up my little python program, the window opened perfectly. Two lessons here: sometimes you just have to walk away. And that usually means a complete reboot that allows your computer to do its own retreat.
I am having fun doing some learning and being able to access it on my laptop is much more natural. I think I’ll be able to find more pockets of time including in hotel rooms now that I don’t have to carry all the peripherals. The RPi and a short ethernet cable are all I need.