Everyone gets stuck at some point when they’re learning to program. So, one of the most important skills to learn as a programmer is how to get unstuck efficiently. This appendix outlines several ways to help you get going again when programming gets confusing.
When you’re stuck, your first step should be to assess your situation. Before you ask for help from anyone else, answer the following three questions clearly:
Make your answers as specific as possible. For the first question, explicit statements like “I’m trying to install the latest version of Python on my new Windows laptop” are detailed enough for others in the Python community to help you. Statements like “I’m trying to install Python” don’t provide enough information for others to offer much help.
Your answer to the second question should provide enough detail so you won’t be advised to repeat what you’ve already tried: “I went to https://python.org/downloads and clicked the Download button for my system. Then I ran the installer” is more helpful than “I went to the Python website and downloaded something.”
For the third question, it’s helpful to know the exact error messages you received, so you can use them to search online for a solution or provide them when asking for help.
Sometimes, just answering these three questions before you ask for help from others allows you to see something you’re missing, and helps get you unstuck without having to go any further. Programmers even have a name for this: rubber duck debugging. The idea is that if you clearly explain your situation to a rubber duck (or any inanimate object) and ask it a specific question, you’ll often be able to answer your own question. Some programming teams even keep a real rubber duck around to encourage people to “talk to the duck.”
Just going back to the start and trying again can be enough to solve many problems. Say you’re trying to write a for loop based on an example in this book. You might have only missed something simple, like a colon at the end of the for line. Going through the steps again might help you avoid repeating the same mistake.
If you’ve been working on the same problem for a while, taking a break is one of the best tactics you can try. When we work on the same task for long periods of time, our brains start to zero in on only one solution. We lose sight of the assumptions we’ve made, and taking a break helps us get a fresh perspective on the problem. It doesn’t need to be a long break, just something that gets you out of your current mindset. If you’ve been sitting for a long time, do something physical: take a short walk, go outside for a bit, or perhaps drink a glass of water or eat a light snack.
If you’re getting frustrated, it might be worth putting your work away for the day. A good night’s sleep almost always makes a problem more approachable.
The online resources for this book, available at https://ehmatthes.github.io/pcc_3e, include a number of helpful sections about setting up your system and working through each chapter. If you haven’t done so already, take a look at these resources and see if there’s anything that helps your situation.
Chances are good that someone else has had the same problem you’re having and has written about it online. Good searching skills and specific inquiries will help you find existing resources to solve the issue you’re facing. For example, if you’re struggling to install the latest version of Python on a new Windows system, searching for install python windows and limiting the results to resources from the last year might direct you to a clear answer.
Searching the exact error message can be extremely helpful too. For example, say you get the following error when you try to run a Python program from a terminal on a new Windows system:
> python hello_world.py
Python was not found; run without arguments to install from the Microsoft
Store...
Searching for the full phrase, “Python was not found; run without arguments to install from the Microsoft Store,” will probably yield some good advice.
When you start searching for programming-related topics, a few sites will appear repeatedly. I’ll describe some of these sites briefly, so you’ll know how helpful they’re likely to be.
Stack Overflow (https://stackoverflow.com) is one of the most popular question-and-answer sites for programmers, and it will often appear in the first page of results on Python-related searches. Members post questions when they’re stuck, and other members try to give helpful responses. Users can vote for the responses they find most helpful, so the best answers are usually the first ones you’ll find.
Many basic Python questions have very clear answers on Stack Overflow, because the community has refined them over time. Users are encouraged to post updates, too, so responses tend to stay relatively current. At the time of this writing, almost two million Python-related questions have been answered on Stack Overflow.
There’s one expectation you should be aware of before posting on Stack Overflow. Questions are meant to be the shortest example of the kind of issue you’re facing. If you post 5–20 lines of code that generate the error you’re facing, and if you address the questions mentioned in “First Steps” on page 477 earlier in this appendix, someone will probably help you. If you share a link to a project with multiple large files, people will be very unlikely to help. There’s a great guide to writing up a good question at https://stackoverflow.com/help/how-to-ask. The suggestions in this guide are applicable to getting help in any community of programmers.
The official Python documentation (https://docs.python.org) is a bit more hit-or-miss for beginners, because its purpose is more to document the language than to provide explanations. The examples in the official documentation should work, but you might not understand everything shown. Still, it’s a good resource to check when it comes up in your searches, and it will become more useful to you as you continue building your understanding of Python.
If you’re using a specific library, such as Pygame, Matplotlib, or Django, links to the official documentation for it will often appear in searches. For example, https://docs.djangoproject.com is very helpful when working with Django. If you’re planning to work with any of these libraries, it’s a good idea to become familiar with their official documentation.
Reddit is made up of a number of subforums called subreddits. The r/learnpython subreddit (https://reddit.com/r/learnpython) is very active and supportive. You can read others’ questions and post your own as well. You will often get multiple perspectives about the questions you raise, which can be really helpful in gaining a deeper understanding of the topic you’re working on.
Many programmers maintain blogs and share posts about the parts of the language they’re working with. You should look for a date on the blog posts you find, to see how applicable the information is likely to be for the version of Python you’re using.
Discord is an online chat environment with a Python community where you can ask for help and follow Python-related discussions.
To check it out, head to https://pythondiscord.com and click the Discord link at the upper right. If you already have a Discord account, you can log in with your existing account. If you don’t have an account, enter a username and follow the prompts to complete your Discord registration.
If this is your first time visiting the Python Discord, you’ll need to accept the rules for the community before participating fully. Once you’ve done that, you can join any of the channels that interest you. If you’re looking for help, be sure to post in one of the Python Help channels.
Slack is another online chat environment. It is often used for internal company communications, but there are also many public groups you can join. If you want to check out Python Slack groups, start with https://pyslackers.com. Click the Slack link at the top of the page, then enter your email address to get an invitation.
Once you’re in the Python Developers workspace, you’ll see a list of channels. Click Channels and then choose the topics that interest you. You might want to start with the #help and #django channels.