Название: Python For Kids For Dummies
Автор: Scott Brendan
Издательство: John Wiley & Sons Limited
Жанр: Зарубежная образовательная литература
Серия: For Dummies
isbn: 9781119110859
isbn:
✓ Click the close icon for the window that Python’s running in. (This works on any platform.)
✓ On Windows, type Ctrl+Z and then press Enter.
✓ On Linux and Mac, type Ctrl-D.
If you’re on a Mac, make sure you’re using the Ctrl key, not the command key. Also, anytime I mention the Enter key, this means the Return key for you.
As I mention, this book doesn’t cover every single possible potential thing you could do with Python. I just can’t do that in a single book.
Instead, this book exposes you to programming in Python. Sort of like the measles. Use this book as a starting point. If you want more information, you should check out
✓ Python’s online documentation
✓ Python’s introspection features
✓ Professor Internet
✓ Source code (not so much)
Python’s online documentation
The Python documentation pages are available at https://docs.python.org/2.7/. The most helpful sections are listed here:
✓ The Python language reference at https://docs.python.org/2.7/reference/index.html
✓ The Python standard library documentation at https://docs.python.org/2.7/library/index.html
In the left sidebar of the documentation page is a quick search field; you can see it in Figure 1-8. Type your question there and Python will search the documentation for you. It works better if you know the Python keyword, module, or error that you’re interested in.
Figure 1-8: Python’s online documentation can help.
The documentation shows the feature you looked for and a code template for how to use the feature. (See this book’s Introduction for how to read code templates.) These docs have a lot of information, but they assume you know how programmers write documentation. This often makes them hard to understand.
Reading the Python documentation is a skill that you have to master if you want to become a Python master. At the moment, though, don’t worry that it seems like it’s written in a foreign language. Just work through it slowly. As you read more of it, you’ll be able to get more information from it. Soon, docs you couldn’t understand at all will become mind-numbingly boring. Then you’ll know you’re making progress!
Python’s introspection features
The second form of help is Python’s introspection features. Introspection means that the program can tell you about itself. Introspection has a lot of different parts. You’ve already met one of them – the help feature. To understand the others you need to know more about Python, so I introduce the rest as you work your way through the book.
Professor Internet
What I like to call “Professor Internet” is the third form of help. When you search the Internet, make sure you include Python as one of your search terms, followed by the thing you’re wondering about. If you know that it’s part of or related to something else, then include that other thing as a search term as well. For example, don’t search for print, because that’s too broad. Search instead for python print. (Capitalization won’t matter.) Another example is if you were interested in the Button widget of the Tkinter toolset (which you meet at dummies.com/go/pythonforkids) you’d search for python button tkinter.
You use a different search strategy online from what you need for the interactive help.
If ads are in your results, skip them.
Source code
Source code is the final form of help. Keep in mind that Python is an interpreted language. This means that what you read is what the computer executes. As a result, if you want to know how some third-party module does something (the Python core isn’t written in Python, so that won’t help), you can literally look at it and see exactly how it did it. You won’t understand it at first, but no matter. Dive in. It starts making sense after a while.
Check out the Python community that’s out there. Look for Internet forums related to Python. The Stackoverflow website (http://stackoverflow.com/questions/tagged/python) is helpful when I’m figuring out problems.
Often, an Internet search will turn up questions that someone else has already asked. If you know the answer to a question, answer it. If you’re correct, and thorough, you’ll get a good reputation.
Don’t guess at an answer. Only post if you’re sure. Also, don’t give your personal information to anyone online. Stick to the topic of programming.
PEPs
Python changes, or evolves, when you use proposal documents called Python Enhancement Proposals (known as PEPs). Each PEP proposes some change to Python; the change is either used or ignored. They may provide you some history about how one feature or another was added to Python.
You can ignore most PEPs, but do check out the following two when you’re ready to move on from the projects in this book:
✓ PEP 8, Style Guide for Python Code has rules about how to format your Python code. For example, it suggests the amount of indent for code blocks (see Project 2). It also has rules (called conventions) for naming. I did my best to follow PEP 8 rules in this book, but sometimes the lines are longer than they recommend.
✓ PEP 257, Docstring Conventions sets different conventions relating to docstrings. Docstrings explain, in normal language, what a program (or part of one) is doing. You meet docstrings in Project 5.
You don’t have to follow (comply with) with PEPs, but try to. It makes it easier for other people to read your code. Heck, it makes it easier for you to read your code. My earlier Python code isn’t PEP 8 compliant, and going back to it is a real pain. Simple things like capital letters in a name make a difference.
Planet Python and PyCon