Understanding Why Python is So Cool
Many programming languages are available today. In fact, a student can spend an entire semester in college studying computer languages and still not hear about them all. (I did just that during my college days.) You’d think that programmers would be happy with all these programming languages and just choose one to talk to the computer, but they keep inventing more.
Programmers keep creating new languages for good reason. Each language has something special to offer — something it does exceptionally well. In addition, as computer technology evolves, so do the programming languages in order to keep up. Because creating an application is all about efficient communication, many programmers know multiple programming languages so that they can choose just the right language for a particular task. One language might work better to obtain data from a database, and another might create user interface elements especially well.
As with every other programming language, Python does some things excep- tionally well, and you need to know what they are before you begin using
- You might be amazed by the really cool things you can do with Python. Knowing a programming language’s strengths and weaknesses helps you use it better as well as avoid frustration by not using the language for things it doesn’t do well. The following sections help you make these sorts of deci- sions about Python.
Unearthing the reasons for using Python
Most programming languages are created with specific goals in mind. These goals help define the language characteristics and determine what you can do with the language. There really isn’t any way to create a programming language that does everything because people have competing goals and needs when creating applications. When it comes to Python, the main objec- tive was to create a programming language that would make programmers efficient and productive. With that in mind, here are the reasons that you want to use Python when creating an application:
- Less application development time: Python code is usually 2–10 times shorter than comparable code written in languages like C/C++ and Java, which means that you spend less time writing your application and more time using
- Ease of reading: A programming language is like any other language — you need to be able to read it to understand what it Python code tends to be easier to read than the code written in other languages, which means you spend less time interpreting it and more time making essential changes.
- Reduced learning time: The creators of Python wanted to make a pro- gramming language with fewer odd rules that make the language hard to After all, programmers want to create applications, not learn obscure and difficult languages.
It’s important to realize that, although Python is a popular language, it’s not the most popular language out there. In fact, it currently ranks eighth on sites such as TIOBE (http://www.tiobe.com/index.php/content/
paperinfo/tpci/index.html), an organization that tracks usage statistics (among other things). If you’re looking for a language solely for the purpose of obtaining a job, Python is a good choice, but C/C++, Java, C#, or Visual Basic would be better choices. Make sure you choose a language you like and one that will address your application development needs, but also choose on the basis of what you intend to accomplish. Python was the language of the year in both 2007 and 2010 and has ranked as high as the fourth most popular lan- guage in February 2011. So, really, it’s a good choice if you’re looking for a job, but not necessarily the best choice. However, it may surprise you to know that many colleges now use Python to teach coding, and it has become the most popular language in that venue. Check out my blog post at http://blog. johnmuellerbooks.com/2014/07/14/python-as-a-learning-tool for details.
Deciding how you can personally benefit from Python
Ultimately, you can use any programming language to write any sort of appli- cation you want. If you use the wrong programming language for the job,
the process will be slow, error prone, bug ridden, and you’ll absolutely hate it — but you can get the job done. Of course, most of us would rather avoid horribly painful experiences, so it’s important to know what sorts of applica- tions people typically use Python to create. Here’s a list of the most common uses for Python (although people do use it for other purposes):
- Creating rough application examples: Developers often need to create a prototype, a rough example of an application, before getting the resources to create the actual Python emphasizes productivity, so you can use it to create prototypes of an application quickly.
- Designing mathematic, scientific, and engineering applications: Interestingly enough, Python provides access to some really cool librar- ies that make it easier to create math, scientific, and engineering applica- The two most popular libraries are NumPy (http://www.numpy. org/) and SciPy (http://www.scipy.org/). These libraries greatly reduce the time you spend writing specialized code to perform common math, scientific, and engineering tasks.
- Working with XML: The eXtensible Markup Language (XML) is the basis of most data storage needs on the Internet and many desktop applica- tions Unlike most languages, where XML is just sort of bolted
on, Python makes it a first-class citizen. If you need to work with a Web service, the main method for exchanging information on the Internet (or any other XML-intensive application), Python is a great choice.
- Interacting with databases: Business relies heavily on Python isn’t quite a query language, like the Structure Query Language (SQL) or Language INtegrated Query (LINQ), but it does do a great job of interact- ing with databases. It makes creating connections and manipulating data relatively painless.
- Developing user interfaces: Python isn’t like some languages like C# where you have a built-in designer and can drag and drop items from a toolbox onto the user However, it does have an extensive array of graphical user interface (GUI) frameworks — extensions that make graphics a lot easier to create (see https://wiki.python. org/moin/GuiProgramming for details). Some of these frameworks do come with designers that make the user interface creation process easier. The point is that Python isn’t devoted to just one method of creating a user interface — you can use the method that best suits your needs.
Discovering which organizations use Python
Python really is quite good at the tasks that it was designed to perform. In fact, that’s why a lot of large organizations use Python to perform at least some application-creation (development) tasks. You want a programming language that has good support from these large organizations because these organizations tend to spend money to make the language better. Here’s a list of the large organizations that use Python the most:
- Alice Educational Software – Carnegie Mellon University (http:// cmu.edu/corporate/news/2007/features/alice.shtml): Educational applications
- Fermilab (https://www.fnal.gov/): Scientific applications
- com (http://go.com/): Browser-based applications
- Google (https://www.google.com/): Search engine
- Industrial Light & Magic (http://www.ilm.com/): Just about every programming need
- Lawrence Livermore National Library (https://www.llnl.gov/): Scientific applications
- National Space and Aeronautics Administration (NASA) (http://www. gov/): Scientific applications
- New York Stock Exchange (https://nyse.nyx.com/): Browser-based applications
- ObjectDomain (http://case-tools.org/tools/objectdomain. html): Computer Aided Software Engineering (CASE) tools
- Redhat (http://www.redhat.com/): Linux installation tools
- Yahoo! (https://www.yahoo.com/): Parts of Yahoo! mail
- YouTube (http://www.youtube.com/): Graphics engine
- Zope – Digital Creations (http://www.zope.com/): Publishing application
These are just a few of the many organizations that use Python extensively. You can find a more complete list of organizations at http://www.python. org/about/success/. The number of success stories has become so large that even this list probably isn’t complete and the people supporting it have had to create categories to better organize it.
Finding useful Python applications
You might have an application written in Python sitting on your machine right now and not even know it. Python is used in a vast array of applica- tions on the market today. The applications range from utilities that run at the console to full-fledged CAD/CAM suites. Some applications run on mobile devices, while others run on the large services employed by enterprises. In short, there is no limit to what you can do with Python, but it really does help to see what others have done. You can find a number of places online that list applications written in Python, but the best place to look is https://wiki. python.org/moin/Applications.
As a Python programmer, you’ll also want to know that Python development tools are available to make your life easier. A development tool provides some level of automation in writing the procedures needed to tell the computer what to do. Having more development tools means that you have to perform less work in order to obtain a working application. Developers love to share their lists of favorite tools, but you can find a great list of tools broken into categories at http://www.python.org/about/apps/.
Of course, this chapter describes a number of tools as well, such as NumPy and SciPy (two scientific libraries). The remainder of the book lists a few other tools; make sure that you copy down your favorite tools for later.
Comparing Python to other languages
Comparing one language to another is somewhat dangerous because the selection of a language is just as much a matter of taste and personal prefer- ence as it is any sort of quantifiable scientific fact. So before I’m attacked
by the rabid protectors of the languages that follow, it’s important to realize
that I also use a number of languages and find at least some level of overlap among them all. There is no best language in the world, simply the language that works best for a particular application. With this idea in mind, the follow- ing sections provide an overview comparison of Python to other languages. (You can find comparisons to other languages at https://wiki.python. org/moin/LanguageComparisons.)
A lot of people claim that Microsoft simply copied Java to create C#. That said, C# does have some advantages (and disadvantages) when compared to Java. The main (undisputed) intent behind C# is to create a better kind of C/C++ language — one that is easier to learn and use. However, we’re here to talk about C# and Python. When compared to C#, Python has these advantages:
- Significantly easier to learn
- Smaller (more concise) code
- Supported fully as open source
- Better multiplatform support
- Easily allows use of multiple development environments
- Easier to extend using Java and C/C++
- Enhanced scientific and engineering support
For years, programmers looked for a language that they could use to write an application just once and have it run anywhere. Java is designed to work well on any platform. It relies on some tricks that you’ll discover later in the book to accomplish this magic. For now, all you really need to know is that Java was so successful at running well everywhere that other languages have sought to emulate it (with varying levels of success). Even so, Python has some important advantages over Java, as shown in the following list:
- Significantly easier to learn
- Smaller (more concise) code
- Enhanced variables (storage boxes in computer memory) that can hold different kinds of data based on the application’s needs while running (dynamic typing)
- Faster development times
PERL was originally an acronym for Practical Extraction and Report Language. Today, people simply call it Perl and let it go at that. However, Perl still shows its roots in that it excels at obtaining data from a database and presenting
it in report format. Of course, Perl has been extended to do a lot more than that — you can use it to write all sorts of applications. (I’ve even used it for a Web service application.) In a comparison with Python, you’ll find that Python has these advantages over Perl:
- Simpler to learn
- Easier to read
- Enhanced protection for data
- Better Java integration
- Fewer platform-specific biases
Getting Your Own Copy of Python
In This Chapter
▶ Obtaining a copy of Python for your system
▶ Performing the Python installation
▶ Finding and using Python on your system
▶ Ensuring your installation works as planned
reating applications requires that you have another application, unless you really want to get low level and write applications in machine
code — a decidedly difficult experience that even true programmers avoid if at all possible. If you want to write an application using the Python pro- gramming language, you need the applications required to do so. These applications help you work with Python by creating Python code, providing help information as you need it, and letting you run the code you write. This chapter helps you obtain a copy of the Python application, install it on your hard drive, locate the installed applications so that you can use them, and test your installation so that you can see how it works.
Downloading the Version You Need
Every platform (combination of computer hardware and operating system software) has special rules that it follows when running applications. The Python application hides these details from you. You type code that runs on any platform that Python supports, and the Python applications translate that code into something the platform can understand. However, in order for the translation to take place, you must have a version of Python that works on your particular platform. Python supports these platforms:
- Advanced IBM Unix (AIX)
- Amiga Research OS (AROS)
- Application System 400 (AS/400)
- Hewlett-Packard Unix (HP-UX)
- Mac OS X (comes pre-installed with the OS)
- Microsoft Disk Operating System (MS-DOS)
- Operating System 2 (OS/2)
- Operating System 390 (OS/390) and z/OS
- RISC OS (originally Acorn)
- Series 60
- Virtual Memory System (VMS)
- Windows 32-bit (XP and later)
- Windows 64-bit
- Windows CE/Pocket PC
Wow, that’s a lot of different platforms! This book is tested with the Windows, Mac OS X, and Linux platforms. However, the examples could very well work with these other platforms, too, because the examples don’t rely on any platform-specific code. Let me know if it works on your non-Windows, Mac, or Linux platform at John@JohnMuellerBooks.com. The current version of Python at the time of this writing is 3.3.4. I’ll talk about any Python updates on my blog at http://blog.johnmuellerbooks.com. You can find the answers to your Python book-specific questions there, too.
To get the right version for your platform, you need to go to http://www. python.org/download/releases/3.3.4/. The download section is ini- tially hidden from view, so you need to scroll halfway down the page. You see a page similar to the one shown in Figure 2-1. The main part of the page con- tains links for Windows, Mac OS X, and Linux downloads. These links provide
you with the default setup that is used in this book. The platform-specific links on the left side of the page show you alternative Python configurations that you can use when the need arises. For example, you may want to use a more advanced editor than the one provided with the default Python pack- age, and these alternative configurations can provide one for you.
Figure 2-1: The Python download page con tains links for all sorts of versions.
If you want to work with another platform, click the Other link on the left side of the page. You see a list of Python installations for other platforms, as shown in Figure 2-2. Many of these installations are maintained by volunteers rather than by the people who create the versions of Python for Windows,
Mac OS X, and Linux. Make sure you contact these individuals when you have installation questions because they know how best to help you get a good installation on your platform.
Figure 2-2: Volunteers have made
Python available on all sorts of platforms.