Hello! If you've asked for programming help and then someone gave you a link to this page, you probably need to give more information about your problem. In the next section I explain why I'm so slow to reply (or often don't reply at all) but you can skip directly to instructions for how to ask programming questions.
Why I Didn't Reply To Your Email Yet (or Ever)
I often get emails say little more than "Why doesn't my program work?" Often I can't answer them; either I don't have enough information about your problem or you're asking me about something I don't know anything about.
I like helping people learn to code. My books, videos, and online courses (most of which are free) have taught tens of thousands of people how to program. This is great! I'm amazed that the internet lets me cheaply share knowledge. I can reach more people in a few years online than a lifetime at the front of a classroom. But when people send me emails, I can only help one person at a time.
This article teaches you how to ask effective programming questions.
These are bad programming questions:
- "Why doesn't my program work? I tried so many ways but no luck. Can you please help me out?" (What is your program? What's it supposed to do, and what's it doing instead?)
- "Sometimes my program works, but sometimes I get an error when I run it." (What error? What's different between when you get it and when you don't?)
- "My program can't find the file." (What file? What does your code look like?)
- "My program doesn't work. Can you help me?" (Don't ask to ask, just ask.)
They're bad because they don't have enough information for your helper to answer them in one reply. In email conversations, there's a lot of waiting in between emails. To answer your question effectively, we need to cut down the amount of back-and-forth. The best way to do that is to not use email at all! Run through this checklist before clicking Send:
Before you email, consider posting the problem to the /r/inventwithpython subreddit or StackOverflow.
The /r/inventwithpython subreddit can answer your questions about code in my books faster than I can reply to your email.
StackOverflow is good for general programming questions, but read the short How do I ask a good question? page first. (This page is also good to read for anyone asking for programming help in general.)
Before you email, google your question. If you got an error message, copy and paste the exact error message into google.
You're not the first person to encounter this error, and someone else has probably answered your questions already. In this case, you'll get an answer much faster by searching the web for it.
Before you email, learn to use the debugger, and use the debugger.
A debugger lets you run through your code one step at a time, and examine what values are in your variables. IDLE comes with a debugger, and you can also always use the pdb debugger module. A debugger saves you much more time than it takes to learn how to use a debugger.
Put As Much Informataion in Your First Email As Possible
The next best way to cut down on the back-and-forth is to put as much information as possible in your first email. Go through the following checklist:
In your email, don't ask to ask. Just ask.
You don't have to say "I have a question about (something). Can you help me with this?" It isn't rude to just ask your programming question if you've taken the time to include all the information your helper needs to answer it.
In your email, use a descriptive subject line.
Pretend you're talking to a busy colleague and have to sum up your entire question in one sentence. Don't use "I need help" or "Can I ask you a question?" These subjects don't describe your question. I have dozens of emails like these, and it's hard to re-find an email later on.
If you are posting your question somewhere online, descriptive post titles make it easier for search engines to guide future people with your same question to your post (and the followup answers!)
It's rude to use a vague, demanding headline like, "HELP!!! My program keeps CRASHING. WHY DOESN'T ANYONE ANSWER ME?!?!?!1" Please don't do that.
In your email, show that you've done research.
Add something like, "I googled for (terms) and found a StackOverflow post at (url), but I don't understand what this person means when they say (something)." This shows that you respect your helper's time and tried to answer it yourself first. It also gives your helpers some leads to go off of.
In your email, don't just say what your program is doing, but also what the overall goal of your program. Make sure your questions have a question mark!
Emails like "I'm trying download a web page using Requets, but I'm getting stuck while return json format." aren't actually asking a question: There's no question mark! Your helper can't assume what the problem is or what you want your program to do: What do you mean by "getting stuck?" What web page are you downloading and why? What would your program specifically be doing if it was working properly?
With context, your helper can figure out if you're on the wrong path entirely. Maybe this is a problem you don't even need to solve!
In your email, copy and paste the full error message.
Python error messages will look something like this:
Traceback (most recent call last): File "test1.py", line 18, in <module> spam() File "test1.py", line 16, in spam bar() File "test1.py", line 13, in bar foo() File "test1.py", line 4, in foo int(x) ValueError: invalid literal for int() with base 10: 'twelve'
Your helper needs all of this information, especially the line numbers! The line numbers tell your helper exactly where the error is happening. Just telling your helper, "I got SyntaxError" doesn't tell them enough to know what's wrong.
In your email, send a pastebin link to the full source code of your program.
Your helper needs the complete, full source code to figure out what's wrong. Go to a "pastebin" site like https://pastebin.com/ or https://gist.github.com/. This way, your helper can run your program themselves.
Do not copy and paste the source code into the email itself. Blank lines at the top of the code will throw off the line numbers in the error message, and many email programs will get rid of the indentation, which renders the code unrunnable.
Do not send a screenshot of the code (or take a photo of your screen with your smartphone). Your helper often needs to run the code to figure out what's wrong, and they can't copy and paste the code from the image. It's rude to expect them to retype all of your code because you didn't want to.
In your email, say what operating system, operating system version, and version of Python you are using.
There are minor but possibly important differences between operating systems and Python versions. Telling me, "I'm running Python 3.6.2 on Windows 10" helps narrow down what could be causing your problem.
In your email, if you have a question about something in one of my books, tell me which book, chapter, and page number you were reading.
I've written several books, so "I can't get the program in your book to work" doesn't tell me which book and which program.
Going through this checklist makes it much more likely that you'll get a quick answer. It's always better to include too much information than not enough. Providing more information helps me help you. And posting to an online forum like the /r/inventwithpython subreddit allows many people to answer your question while creating a page that people in the future with a similar problem can find.
Good luck, and keep coding!
A common question I get from readers is "what should I study/read/learn next?" If you've read Automate the Boring Stuff with Python, you might want to read my other books for free online. I also recommend Python Crash Course (you can skip directly to the second half if you're comfortable with Python) and Fluent Python and Effective Python. If you want practice writing simple programs, try the practice problems on Exercism.io or the /r/dailyprogrammer subreddit.