diff --git a/installing-python.html b/installing-python.html index 275012f..a6d2b26 100644 --- a/installing-python.html +++ b/installing-python.html @@ -211,38 +211,50 @@ Type "help", "copyright", "credits" or "license" for more information.
FIXME +
Modern Linux distributions are backed by vast repositories of precompiled applications, ready to install. The exact details vary by distribution. In Ubuntu Linux, the easiest way to install Python 3 is through the Add/Remove application in your Applications menu.
+
When you first launch the Add/Remove application, it will show you a list of preselected applications in different categories. Some are already installed; most are not. Because the repository contains over 10,000 applications, there are different filters you can apply to see small parts of the repository. The default filter is “Canonical-maintained applications,” which is a small subset of the total number of applications that are officially supported by Canonical, the company that creates and maintains Ubuntu Linux.
+
Python 3 is not maintained by Canonical, so the first step is to drop down this filter menu and select “All Open Source applications.”
+
Once you’ve widened the filter to include all open source applications, use the Search box immediately after the filter menu to search for Python 3.
-
+
Now the list of applications narrows to just those matching Python 3. You’re going to check two packages. The first is Python (v3.0). This contains the Python interpreter itself.
+
The second package you want is immediately above: IDLE (using Python-3.0). This is a graphical Python Shell that you will use throughout this book.
+
After you’ve checked those two packages, click the Apply Changes button to continue.
+
The package manager will ask you to confirm that you want to add both IDLE (using Python-3.0) and Python (v3.0).
+
Click the Apply button to continue.
+
The package manager will show you a progress meter while it downloads the necessary packages from Canonical’s Internet repository.
+
Once the packages are downloaded, the package manager will automatically begin installing them.
+
If all went well, the package manager will confirm that both packages were successfully installed. From here, you can double-click IDLE to launch the Python Shell, or click the Close button to exit the package manager.
+
You can always relaunch the Python Shell by going to your Applications menu, then the Programming submenu, and selecting IDLE.
+
The Python Shell is where you will spend most of your time exploring Python. Examples throughout this book will assume that you can find your way into the Python Shell.
FIXME +
Python 3 is available on a number of different platforms. In particular, it is available in virtually every Linux, BSD, and Solaris-based distribution. For example, RedHat Linux uses the yum package manager; FreeBSD has its ports and packages collection; Solaris has pkgadd and friends. A quick web search for Python 3 + your operating system will tell you whether a Python 3 package is available, and how to install it.
⁂
FIXME +
The Python Shell is where you can explore Python syntax, get interactive help on commands, and debug short programs. The graphical Python Shell (named IDLE) also contains a decent text editor that supports Python syntax coloring and integrates with the Python Shell. If you don’t already have a favorite text editor, you should give IDLE a try. + +
First things first. The Python Shell itself is an amazing interactive playground. Throughout this book, you’ll see examples like this: + +
+>>> 1 + 1 +2+ +
The three angle brackets, >>>, denote the Python Shell prompt. Don’t type that part. That’s just to let you know that this example is meant to be followed in the Python Shell. + +
1 + 1 is the part you type. You can type any valid Python expression or command in the Python Shell. Don’t be shy; it won’t bite! The worst that will happen is you’ll get an error message. Commands get executed immediately (once you press ENTER); expressions get evaluated immediately, and the Python Shell prints out the result. + +
2 is the result of evaluating this expression. As it happens, 1 + 1 is a valid Python expression. The result, of course, is 2. + +
Let’s try another one. + +
+>>> print('Hello world!')
+Hello world!
+
+
+Pretty simple, no? But there’s lots more you can do in the Python shell. If you ever get stuck — you can’t remember a command, or you can’t remember the proper arguments to pass a certain function — you can get interactive help in the Python Shell. Just type help and press ENTER. + +
+>>> help +Type help() for interactive help, or help(object) for help about object.+ +
There are two modes of help. You can get help about a single object, which just prints out the documentation and returns you to the Python Shell prompt. You can also enter help mode, where instead of evaluating Python expressions, you just type keywords or command names and it will print out whatever it knows about that command. + +
To enter the interactive help mode, type help() and press ENTER. + +
+>>> help() +Welcome to Python 3.0! This is the online help utility. + +If this is your first time using Python, you should definitely check out +the tutorial on the Internet at http://docs.python.org/tutorial/. + +Enter the name of any module, keyword, or topic to get help on writing +Python programs and using Python modules. To quit this help utility and +return to the interpreter, just type "quit". + +To get a list of available modules, keywords, or topics, type "modules", +"keywords", or "topics". Each module also comes with a one-line summary +of what it does; to list the modules whose summaries contain a given word +such as "spam", type "modules spam". + +help>+ +
Note how the prompt changes from >>> to help>. This reminds you that you’re in the interactive help mode. Now you can enter any keyword, command, module name, function name — pretty much anything Python understands — and read documentation on it. + +
+help> print ① +Help on built-in function print in module builtins: + +print(...) + print(value, ..., sep=' ', end='\n', file=sys.stdout) + + Prints the values to a stream, or to sys.stdout by default. + Optional keyword arguments: + file: a file-like object (stream); defaults to the current sys.stdout. + sep: string inserted between values, default a space. + end: string appended after the last value, default a newline. + +help> PapayaWhip ② +no Python documentation found for 'PapayaWhip' + +help> quit ③ + +You are now leaving help and returning to the Python interpreter. +If you want to ask for help on a particular object directly from the +interpreter, you can type "help(object)". Executing "help('string')" +has the same effect as typing a particular string at the help> prompt. +>>> ④+
print() function, just type print and press ENTER. The interactive help mode will display something akin to a man page: the function name, a brief synopsis, the function’s arguments and their default values, and so on. If the documentation seems opaque to you, don’t panic. You’ll learn more about all these concepts in the next few chapters.
+IDLE, the graphical Python Shell, also includes a Python-aware text editor. You’ll see how to use it in the next chapter.
⁂
FIXME -
-http://wiki.python.org/moin/PythonEditors -http://wiki.python.org/moin/IntegratedDevelopmentEnvironments -http://pydev.sourceforge.net/ -http://www.activestate.com/komodo/ -http://www.activestate.com/activepython/ -+
IDLE is not the only game in town when it comes to writing programs in Python. While it’s useful to get started with learning the language itself, many developers prefer other text editors or Integrated Development Environments (IDEs). I won’t cover them here, but the Python community maintains a list of Python-aware editors that covers a wide range of supported platforms and software licenses. + +
You might also want to check out the list of Python-aware IDEs, although few of them support Python 3 yet. One that does is PyDev, a plugin for Eclipse that turns Eclipse into a full-fledged Python IDE. Both Eclipse and PyDev are cross-platform and open source. + +
On the commercial front, there is ActiveState’s Komodo IDE. It has per-user licensing, but students can get a discount, and a free time-limited trial version is available. + +
I’ve been programming in Python for nine years, and I edit my Python programs in GNU Emacs and debug them in the command-line Python Shell. There’s no right or wrong way to develop in Python. Find a way that works for you!