About this book

This book is intended for people who already have experience in one or more programming languages and want to learn the basics of Python 3 as quickly and directly as possible. Although some basic concepts are covered, there's no attempt to teach basic programming skills in this book, and the basic concepts of flow control, OOP, file access, exception handling, and the like are assumed. This book may also be of use to users of earlier versions of Python who want a concise reference for Python 3....

Adding more Python libraries

Finding a Python package or module can be as easy as entering the functionality you're looking for, like mp3 tags and Python into a search engine, and then sorting through the results. If you're lucky, you may find the module you need packaged for your OS with an executable Windows or Mac OS X installer or a package for your Linux distribution. This is one of the easiest ways to add a library to your Python installation, because the installer or your package manager takes care of all the...

Scoping rules and namespaces for class instances

Now you have all the pieces to put together a picture of the scoping rules and namespaces for a class instance. When you're in a method of a class, you have direct access to the local namespace (parameters and variables declared in the method), the global namespace (functions and variables declared at the module level), and the built-in namespace (built-in functions and built-in exceptions). These three namespaces are searched in the following order local, global, and built in (see figure...

Screen inputoutput and redirection

You can use the built-in input method to prompt for and read an input string > > > x input(enter file name to use ) enter file name to use myfile > > > x 'myfile' The prompt line is optional, and the newline at the end of the input line is stripped off. To read in numbers using input, you need to explicitly convert the string that input returns to the correct number type. The following example uses int > > > x int(input(enter your number )) enter your number 3 9 > > > x...

What Python does well

Python is a modern programming language developed by Guido van Rossum in the 1990s (and named after a famous comedic troupe). Although Python isn't perfect for every application, its strengths make it a good choice for many situations. Programmers familiar with traditional languages will find it easy to learn Python. All of the familiar constructs such as loops, conditional statements, arrays, and so forth are included, but many are easier to use in Python. Here are a few of the reasons why...

Alternatives to Tkinter

It isn't particularly fast and isn't a good candidate for games or for image-manipulation programs. Its high-level approach means that particularly unusual or specialized user interfaces may be difficult to implement. Or, you may not have the time to learn Tkinter. Fortunately, alternatives are available. Three cross-platform windowing GUI libraries stand out, being available for at least Windows, Mac OS X, and Linux UNIX. The first is the Qt package, which...

Browsing Python documentation on your computer

Many distributions of Python include the full documentation by default. In some Linux distributions, the documentation is a separate package that you need to install separately. In most cases, however, full documentation is already on your computer and easily accessible. Accessing help in the interactive shell or at a command line In chapter 2, you saw how to use the help command in the interactive interpreter to access online help for any Python module or object gt gt gt help int Help on int...