Quantcast

Start with 7 free days of training.

Gain instant access to our entire IT training library, free for your first week.
Train anytime on your desktop, tablet, or mobile devices.

On-the-job Training

This course will be retired in 292 days. If you have questions, please contact us.

This video training with Tim Warner covers the basics of writing computer programs including control flow, file handling, and more....
This video training with Tim Warner covers the basics of writing computer programs including control flow, file handling, and more.

Recommended skills:
  • Some familiarity with programming

Recommended equipment:
  • Latest version Python software

Related certifications:
  • Not applicable

Related job functions:
  • Desktop/web developers
  • System administrators
  • Programmers
  • Instructors
  • Students


If you're interested in learning how to write computer programs, you'll love this training. It's perfect for desktop/web application developers who need an intro course in Python, for systems administrators who are interested in using Python for automation and for anyone interested in a programming career.

By the time you're done watching, you'll be ready to develop Python automation scripts, desktop apps, and/or Web apps.

You'll also have a thorough knowledge of how to use Python on all major platforms and a healthy jumpstart for learning other programming languages (like Java, Perl, C and Ruby).
 show less
1. Course Introduction (42 min)
2. Introduction to Python (44 min)
3. Data Types, Part I (46 min)
4. Data Types, Part II (34 min)
5. Statements, Documentation, and Help (44 min)
6. Strings, Revisited (26 min)
7. Control Flow, Part I (27 min)
8. Control Flow, Part II (25 min)
9. Data Structures, Revisited (32 min)
10. Functions (50 min)
11. File Handling (44 min)
12. Accessing the Network and Internet (35 min)
13. Exception Handling (37 min)
14. Modular Programming (37 min)
15. Object-Oriented Programming (30 min)
16. Advanced Topics (18 min)
17. GUI Development (22 min)
18. Python and Database Access (22 min)
19. Porting Python Code (16 min)
20. Python Frameworks and IDEs (23 min)

Course Introduction

00:00:00

Hello, and welcome to the CBT Nugget series, Learning to Program With Python. My name is Tim Warner, and I'm happy and grateful to be your instructor. Let's take a look at our agenda for this introductory Nugget. First, we're going to look at how this course works.

00:00:15

I want to let you know for whom I designed this course, to make sure that you are, indeed, in the right course of study. Chances are, if you've come this far, you are. We'll then look at what you need to get started with this course. This course I've designed as a true workshop environment.

00:00:33

I'll show you where to get the exercise files that accompany the course, and so long as you have Python installed on one of your computers, and you're simultaneously watching this Nugget, you've got everything you need to learn Python language. Speaking of Python, we're going to complete this introductory Nugget by examining exactly what is Python, and why is it such a hot programming language now in the 21st century.

00:00:57

Who is this series designed for? The main audience for this title are newcomers to programming, people with no previous experience with software or application development. Now this could involve a few different populations of folks. For instance, you might be, unfortunately, a victim of the poor economy as of this recording in 2010, and perhaps you're between jobs.

00:01:21

Maybe you're moving from another role in IT, and you want to come into programming, or perhaps you're entering IT brand new from a completely different field, and because of your interest and aptitude, you feel that application development is a really good step for you.

00:01:37

Well, if you fall into this category, special welcome to you. By the time you finish this series, you'll be absolutely, not just walking, but I would say jogging, if not running, in your programming skills. And you'll have Python under your belt, which is not too bad at all as far as porting those skills to other languages that are used in industry today.

00:01:57

Another population of folks for whom this title would be relevant are those who are simply interested in knowing more about programming. Perhaps you work as a systems administrator, and you want to understand some of the hows and whys behind the applications and servers that you maintain.

00:02:13

Or alternatively, perhaps you work in a software development shop, not as a programmer but in a paraprogramming role-- maybe content development, et cetera-- and it would increase your efficiency at work if you had some programming knowledge under your belt, and it would allow you to speak the developers' language more effectively.

00:02:32

And that actually ties into this third party for whom this series is most appropriate, and that is folks currently in IT who are required to learn programming. In particular, you may have a migration to Python going on in your shop. Maybe you're proficient with other application languages, and now you're kind of under the gun to learn Python.

00:02:53

Welcome to all of you newcomers. Now what if you already do have experience with other programming paradigms and programming languages? Are you being left out in the dust in this series? I don't think so. I also try to keep those developers who want or need Python skills to the forefront of my mind.

00:03:11

Now I'm not going to assume anything with regard to your previous experience in programming. I'm actually, like I said, assuming nothing, so we're starting from the ground floor up. Therefore, if you are an experienced developer-- in contrast to a newcomer, who will certainly want to watch the videos in this Nugget series sequentially, one after the other in order-- perhaps a seasoned developer can pick and choose which specific Nuggets that he or she wants, so that you don't cover ground that you've already completely mastered.

00:03:40

Nonetheless, I truly believe that I add enough value to this course that even seasoned developers will come away learning some really nifty stuff that they didn't know prior to starting this course. OK, next question I think that's relevant is why are we doing Python?

00:03:55

I mean, if this is a bare bones, brand new, newcomer to programming, learn to program course, why didn't we choose another programming language? Perhaps C, or C++, or even a more contemporary language like Java or C#. Python actually is very, very popular in academia, not just higher education or college university level, but also in the K-12 space.

00:04:20

Python is used very, very much as a learning language. It just is. In fact, let me jump down to this bottom bullet point first. There is a plethora, to say the very least, of tutorials-- videos, like the CBT Nugget series, books, online walkthroughs, et cetera-- on learning Python.

00:04:39

Therefore, you pretty much can't help but pick up some Python if you're brand new to programming and you're scouring the web, or checking out your local community college to see if there's a night course in the fundamentals of programming. Now what I've said thus far is all well and good, and reflects reality, but does not yet answer the question, why Python?

00:04:58

Well, first of all, Python is used as a development language, a training language, first of all because it's not a "toy" language. It's an actual, honest to goodness scripting development environment that you can use to solve real-world problems, and it is being used.

00:05:15

A little later in this particular Nugget, I'll give you some very high-profile companies and applications that use, or in the case of applications, were written in Python. Python is actually based, in large part, on-- I wouldn't exactly call it a "toy" language, but it's almost exclusively used for learning, and not for real-world industry stuff-- and that is the programming language called ABC.

00:05:38

This is a imperative general purpose programming language. It was developed in the Netherlands, and was used by the founder and the creator of Python, Guido van Rossum. We'll talk more about him in just a moment. He was using ABC, and wanted to develop a language that used a lot of the same constructs and methodology as ABC-- ease of use, for instance, being principal-- and apply it to his real-world Unix/Linux systems administration tasks.

00:06:05

So again, Python is great because you can actually start to apply what you're learning to solve real-world problems. Another reason why Python is a great learning language is that it's a high-level programming language. We can compare that with a low-level programming language, like C. We'll talk more about the difference between high- and low-level languages shortly.

00:06:25

A third advantage to Python is its speed. As we're going to see, we're going to be working with its interactive mode a lot over the course of the next 20 or so Nuggets. And what interactive mode means is that we're interacting with the Python interpreter in a live session.

00:06:40

That is to say, we can issue statements and commands, and the Python interpreter will interpret or process those commands immediately, and give us instant feedback. Therefore, you wind up with Python doing quite rapid development when compared to traditional, fully compiled languages like C, where in order to test your code, you actually have to pause while the compiling and linking process takes place.

00:07:05

In other words, your source code is converted to machine language, and then that machine language is executed by the operating system. Now let's have a look at the basic course structure for the CBT Nugget series, and Learning to Program With Python.

00:07:19

We're going to-- to quote Lewis Carroll from Alice's Adventures in Wonderland-- begin at the beginning, proceed until the end, and then stop. Now yeah, I'm being kind of funny there, but that's really what we're going to do. Consider a swimming pool that gradually moves from the shallower side to the deeper side, a very linear progression.

00:07:37

Well, that's what we're going to do here. We're going to start off with what is Python, how do we get it installed, what does it look like, what's the difference between writing a Python script file and running it versus working in interactive mode. And then we'll look at data types, declaring variables, working with operators, and operations.

00:07:57

We'll look at documentation and how to handle that. We're going to see that a basic thread that runs through the Python programming language is its legibility. In fact, that's principally why Guido van Rossum developed Python. He wanted a functional language, a language that really allows you to get done the work you want to get done, but then anyone else reviewing your code, including yourself six months later, will be able to easily figure out what's going on just by looking at the code itself.

00:08:24

Course, we can add additional documentation to make the code even more easy to read. Good stuff. Then we'll look at the basic building blocks of most procedural programs. We have operators, strings, more complex data structures like lists, and tuples, and dictionaries.

00:08:41

We'll look at flow control and looping mechanisms, functions, or also called subroutines. They're going to allow you to begin to modularize your Python application so it's not just a straight string of code. You might remember, way back when, I myself started programming in the very early '80s.

00:08:59

I believe it was 1981 or 1982, with the Commodore 64 and its implementation of the BASIC programming language. There, you might remember, you just had a block, a numbered block of statements, and you could use GOTO and GOSUB to get around and stuff, but to say that this was a clunky way to develop applications is an understatement.

00:09:22

We're going to then look at some of the neat things that Python can do, like touching files, and going out onto the file system, hitting your local area network, and even the web. In order to be an effective application developer in any language, we have to master the art of debugging, which is really an art and a science.

00:09:40

The good news is that the Python interpreter comes with built-in functionality for debugging and handling exceptions. We're going to learn what all these terms mean as we go along. Remember, I'm not assuming that you have any familiarity with any of these technical terms.

00:09:55

What would be interesting, I think, is you're watching this movie now. When you finish all of the Nuggets in the series, and after you've had some time, some hands-on experience with Python, I'd like you to come back and re-watch this particular part of this Nugget and ask yourself, do I now understand all these terms?

00:10:12

And I'm confident you will definitely be able to say yes. Modular programming and OOP. As we're going to see as we go along, yet another advantage of Python that makes it very flexible, as well as a great learning language, is that it's a multi-paradigm language, that you can use multiple different development styles.

00:10:30

You can use functional programming and/or object-oriented programming, depending upon your own comfort level, and what's being done in your shop. Python is equally adept at the console-based application, where you're just interpreting the raw text with no windowed graphical interface, but we also have plenty of modules available to help us build honest to goodness graphical user interfaces, and these would be run as desktop applications and/or web applications.

00:10:59

Remember, key word here, flexibility. Python is all about flexibility. Speaking of flexibility, the main way to extend a default installation of Python and support some of these other neat features-- like, say, GUI development, file handling, accessing the network, doing scientific and mathematical operations-- you'll want to install one or more Python external packages or modules.

00:11:22

And I'll also introduce you to the popular Integrated Development Environments. IDEs are a graphical way to better handle the code generation and debugging process. More on that later. As I stated earlier in this Nugget, I'm not only going to be giving you theoretical information on white boards, and tons of live demos using the Python interpreter, but I'm also going to be simultaneously, in parallel, saving all of my source code as separate .py files, and make those available to you at nuggetlab.com.

00:11:55

Now if you're not aware of nuggetlab.com, this is a location at the CBT Nuggets website hierarchy, where you can download work files for any CBT Nuggets product that has those work files. So bottom line, you'll want to make sure to hit up nuggetlab.com and download the Python exercise files.

00:12:13

I'm also going to throw in a lot of other neat stuff beyond simply the source code. For instance, I'll make sure to give you a comprehensive, hand-selected links list that gives you what I consider to be the best on the web as far as internet resources for learning Python.

00:12:29

So what do you need to get started? I've covered half of it in the previous white board. You'll want to go to nuggetlab.com and snag the exercise files, and unpack that zip file, and have those files ready to rock. The other thing, of course, that you'll need is Python, an installation of Python.

00:12:44

Now those of you who do have experience with Python are immediately seeing that we're covering Python 3 in this Nugget series. As of this recording in April, 2010, the two stable releases of Python are 2.6.5 and 3.1.2. Now the question comes up, why am I choosing 3?

00:13:05

Well, on one very practical aspect, we're going to have more longevity with these lessons, because 3 will eventually completely supersede version 2. Now we don't need to get into the specifics here too much at this point, but there are some key changes in functionality between Python 2.6 and version 3.

00:13:25

One big example that comes to my mind immediately, and actually to most Python people immediately, is that in Python 2.6, the print statement was just that. If you wanted to display screen output, you would just type print and then pass in your string.

00:13:41

In Python 3, that actually will return an error. In Python 3, print statement has become a function. So it's a little bit subtle here. You still have your quoted string-- that's going to be the text, or the string content that's displayed to the output-- but because it's a function instead of a statement, you need to enclose the quoted string within parentheses, you see?

00:14:03

Now here's the good news, friends. Yes, it's best practice, I think, to use the latest version, version 3, because that's what we've got going forward, certainly. I will also-- when we hit stuff like the print statement that's now the print function-- I will give you a flag in the training to let you know, hey, it worked this way in Python 2, and this way in Python 3, so you won't be completely lost.

00:14:25

Although 3 is gaining more and more foothold in the market, you will find that some Python-based applications still rely upon 2.6, or even 2.5. Regardless, what you'll want to do to download either of these versions-- I would certainly recommend 3 for this training-- is visit the Python download homepage at python.org/download.

00:14:47

Now you can run and use Python, and access the course content just fine, running Windows, Mac OS X, or *nix. *Nix means, of course, Unix or Linux. However, although the vast majority of this Nugget series will work fine regardless of your operating system, I'm going to be using Windows for my operating system of choice, so in some cases, you might find a slight variation if you're using a non-Windows OS.

00:15:14

For instance, when we get to the Nugget on manipulating files in the file system, on my Windows box, I'm going to be using directory paths as we do in Windows, but you'll want to substitute those paths for Mac OS X-specific paths, or *nix-specific paths, if you're using those operating systems.

00:15:32

So keep that in mind. Enough with the hubbub. What is Python formally defined? Python is formally defined as a general-purpose high-level programming language that features a high degree of readability and user friendliness. OK, let's take each part of that definition in part, shall we?

00:15:49

First let's look general-purpose. It's general-purpose because Python is not specifically targeted to a specific what's called an application domain. You're going to be picking up, as a byproduct of this Nugget series, a lot of honest to goodness programmer speak, or developer speak.

00:16:06

And in the literature, you'll find references to problem domains, or application domains, as the specific context in which your application runs. For instance, you may have an application domain that targets the web browsers in traditional world wide web access.

00:16:21

You may have another application or problem domain that mandates a desktop application that's installed locally on a user's operating system. Especially now, in 2010, a common application or problem domain is getting your code to run on mobile devices-- the Apple iPhone, the iPod Touch, and now, what's just brand new and I can't wait to get my hands on, the iPad.

00:16:43

So general-purpose means that we can use Python to address a number of different application domains. High-level programming language, well, this bespeaks the distinction between a high-level and a low-level programming language, doesn't it? Basically, a high-level programming language is going to abstract or hide the gooey, gory details of underlying hardware, and the host operating system.

00:17:09

A programming language like C is considered a low-level language. When you're programming in C, you're actually mapping out memory address registers in RAM, and you're defining calls that go right down to the nooks and crannies of the host operating system, and in some cases interact directly with the hardware and the processor on the system.

00:17:31

Some folks really like that power that C has, but C also has a very steep learning curve. It has security issues. For instance, if you're not allocating the right amount of memory, and not performing bounds checkings on the memory that you're allocating your C application, you can have a malicious user crash that app using something called a buffer overflow.

00:17:52

If you have experience in IT, especially systems administration, I'm sure you've heard about that. On the other hand, Python, as a high-level language, involves your source code being interpreted, or read line by line, by what's called a virtual machine.

00:18:08

Now whereas a C application, once you can compile it, that's really all you need, is the executable, and perhaps, like in the case of Windows, you might have external libraries stored as DLL files that are called. But other than that, a fully compiled application, written in a low-level language like C, is largely a standalone unit.

00:18:28

Now Python, you have to have a runtime environment on the host operating system to catch the Python code. This presents a little bit of a challenge in Windows, whereas *nix and Mac OS X systems have the Python interpreter slash virtual machine installed by default.

00:18:46

You can test that by simply opening up a command prompt on a Mac box, or on a Linux machine, and simply typing Python. On the other hand, in Windows, like I said, you'll have to take the extra step of installing the Python interpreter, and then the interpreter interprets your Python source code, and the VM presents an abstraction layer that hides the underlying processor architecture and OS details.

00:19:10

Now that's actually good news. You might think, well, aren't I missing something by having all this control? And I think you're more than making up for that lack of control, that direct access to the processor, memory, et cetera, by improving portability, and we'll talk more about that in a second.

00:19:26

But yet another of Python's virtues is that this Python virtual machine, as I just told you, is available on, at the least, Windows, Linux, and Mac OS X. So this means your Python code will be interpreted as-is, without any porting, without any code conversion, on all three of those OSes.

00:19:45

Isn't that great? Another aspect of the Python programming language is that it's a multi-paradigm language. Paradigm is a $5 term that in this context simply means programming style. The biggies are procedural, also called imperative, programming style, and object-oriented programming style.

00:20:03

We're going to begin covering Python in a procedural way, because I think this is more intuitive to the beginning programmer. Procedural programming involves-- you guessed it-- procedures, where we're not fully modularizing our code into objects like we are in an object-oriented environment, but we're taking firmer control over how the code executes, the direction, the ways that the code can branch, et cetera.

00:20:30

In procedural programming, we have that mapped out pretty, pretty strictly. But because Python is multi-paradigmatic-- I believe that's the word-- you can also use functional as well as object-oriented. We're actually going to spend a Nugget discussing how to use Python in an object-oriented fashion, simply because OOP, as it's called, is a super, super popular, hot, and flexible programming paradigm.

00:20:54

So who runs Python anyway? Who's the man or woman in charge? It's actually a nonprofit organization called the Python Software Foundation. The president of the Python Software Foundation is the man who invented the language. This is a Dutch programmer named Guido van Rossum, and as I told you a little bit earlier, he came across developing Python.

00:21:15

It's an interesting story. If you look him up on Google, you can read his own account of how he developed the language. But basically, he wanted an easy to understand, easy to read, easy to use language to perform routine systems administrative tasks, kind of like a shell script on steroids.

00:21:32

And as I also mentioned earlier, Python owes a lot of its code base, and its operation, to the purely teaching, or so-called "toy" language, ABC. Another interesting thing about Python is the licensing scheme. It's extremely flexible. Python is certified open-source software, but it has an even more permissive scheme than what you find in the GNU Public License, or GPL, that many open-source products use.

00:21:57

You can use Python in your application, you can bundle your application and sell the application for however much money you want, and you don't owe the Python Software Foundation a penny. Pretty much the only requirement that they have is you leave their copyright notice in your source code.

00:22:14

Other than that, you can do what you want-- for profit, for community spirit, whatever-- with the Python interpreter, as well as the language. And that's actually another neat thing. If you want to do programming in, say, Adobe Flex, and Adobe AIR-- that's another really hot technology nowadays-- you have to ask Adobe for permission, and obtain a license, in order to bundle their AIR runtime with your software.

00:22:38

Not so with Python. You can just go right through without jumping through any of those hoops. One very natural and obvious question that comes to those who are new to Python, especially systems administrators who have worked with other scripting languages, is the question, is Python scripting language or a programming language, and what's the difference between those?

00:22:59

The short answer, to cut to the chase, is that Python is officially both a scripting language and a fully fledged programming language. Now traditional examples of traditional scripting languages include Windows and/or *nix shell scripts that inter-operate directly with the host OS, Apple Script for Mac OS X platforms.

00:23:22

If you've done web development in the past, then you're probably familiar with JavaScript and Perl. Systems administrators in Windows used to do a lot of automation-- and still do, for that matter, with VBScript, the script version of the Visual Basic programming language.

00:23:37

And more recently, Windows PowerShell has really matured quite nicely over the last few years, and is also a really nice scripting environment. Now what defines a scripting language? That's where opinions start to vary a little bit. Generally speaking, scripting languages are not compiled directly to source code and kept that way.

00:23:58

The classic example I gave you earlier was the C programming language. When you run that through the compiler, you wind up with machine language. This is really super low-level code that interacts directly with the hardware and the host operating system on the computer on which that program is running.

00:24:16

You'll recall from earlier in this Nugget, we talked about Python being an interpreted language. That is to say, you have the Python interpreter slash virtual machine installed or resident on that server computer or workstation computer, and your source script file is interpreted.

00:24:33

First it's converted to an intermediary form called byte code. This intermediary code is not anywhere near as low-level as raw machine code, but you'll recall from our discussion earlier that byte code is actually pretty cool, because it interacts with any Python virtual machine.

00:24:49

So we could be running, underneath the virtual machine, Linux, Windows or Mac, and then even underneath that, at the hardware level, we could be dealing with a 64-bit or a 32-bit processor. It really doesn't matter. So scripting languages are generally interpreted.

00:25:05

And when you think of interpretation, what that actually means, I like to draw the metaphor to giving an actor or a professional speaker a script file, and you ask that person to read the file. Well, if they interpret the contents of that script, they're going to go line by line, from top down to the bottom, until it's finished.

00:25:24

That's very similar to how interpreted scripting languages work. Now, of course, to every method, there is an alternate method. Although this interpretation is, generally speaking, how Python works, there are occasions where you do want to have a compiled end product, a standalone application.

00:25:43

And this is where we can start to cross over from scripting to full fledged programming language. There's a module called py2exe, for instance, you can use to create a fully fledged, say, Windows executable program file, from your Python source code.

00:25:58

Another really great advantage of using py2exe, and coming out at the end of the day with a machine language executable, is that you don't have to worry about having the Python virtual machine installed on all of your users' boxes, you see? Another differentiation that some folks make with Python, as being both a scripting and a programming language, is that generally speaking, a script file is a single file, and that script file's, generally speaking, created to accomplish a specific goal.

00:26:26

Whereas multifile files-- where we have multiple .py files, and then we have perhaps several code files, and then several other .py files that are modules, or function libraries that are brought in-- that's where you start to go from traditional definition of scripting to a much more robust application environment.

00:26:48

Finally, scripting languages normally are instantiated by being embedded in other applications, traditionally the applications that they control. Good examples of this functionality would be if you've ever used Sun Microsystems VirtualBox software. VirtualBox is a really nifty virtualization software.

00:27:08

Fact, I use this particular one even more than, say, Microsoft's Virtual PC, or even VMware Workstation. It's great, and what's even greater about it is that it has built-in support for Python scripting, to where you can automate a lot of virtual machine tasks-- say the batch creation, the batch management of virtual machine files-- by using a Python interface.

00:27:32

Civilization IV, the famous computer game, is another example of a host application that enables users to customize the environment at a pretty deep level by using Python. So I hope that I've made the situation a little bit clearer that Python is both a traditional scripting language-- a single file that's used to accomplish a specific goal, and generally speaking, just interpreted directly by the Python interpreter-- and it also has features of a full fledged programming language.

00:28:02

You can find ways to compile your Python code into machine language, for instance, and you can also use Python separately, or embedded in another application. Another relevant question, why would we want to use Python in the real world? You might be thinking now, OK, Tim, I'm sold that Python is the right language for me to use to start learning about computer programming, and I also accept what you said that Python's a great learning and teaching language, because it is a real-life language.

00:28:31

Why don't you back that up now with some facts? Well, here I go. Python is used in the real world for a variety of good reasons. One is its rapid development. Generally speaking, you can do the same thing in Python with a smaller amount of code-- some say one third as much code as, say, a comparable C++ or Java application-- and you can also run that code in a testing environment far faster than you can with compiled applications.

00:28:59

If you've used the .NET framework with Microsoft, for instance, those are all compiled applications. So you would use, say, C# to build, and then when it comes time to test, there's actually a delay because the integrated development environment-- a.k.a.

00:29:14

Visual Studio, if you're using that one-- has to run through the compilation and link process before giving you the app in a runtime environment. By contrast, because Python is interpreted by the Python VM, you can just test to your heart's content, both in running external script files, or as I said earlier-- and we're going to get to know very well in just a short amount of time-- we can work with the Python interpreter interactively, and get direct feedback as we're trying things out.

00:29:43

Another huge reason, a huge selling point of Python, is its portability. Python is similar to Java. Now Java, again, is one of those in-between languages that uses interpretation and compilation. But the reason why I draw an analog line between Python and Java is because, well, number 1, both of those use a virtual machine, and that virtual machine or interpreter has to be installed on each computer that's going to run that Python or Java code.

00:30:13

The second reason why I link Python and Java is that they're both eminently portable, which I've already said several times. This is cross-platform portability, being able to run the same code, without making changes to the source, on a variety of different hardware and software platforms.

00:30:29

Python, as I've said earlier, is eminently flexible and extensible. There exists a wide variety of libraries. These are external modules-- in most cases, .py files, just like your own source-- but the developer or developers who created that library for you have saved you a lot of work to accomplish certain functions in Python.

00:30:49

For instance, what if you want to create a Python application that uses FTP functionality? While the built-in libraries that ship with the Python interpreter are robust and rich, you'll need to go to third-party sources to get specialized functionality.

00:31:05

So you can download a network-oriented module to handle things like TFTP, simple mail transfer protocol, HTTP, the list goes on. The bottom line is you can find a module for just about anything you'd ever want to do in Python. It's really nice. Yet another great reason to use Python in the real world is its integration with other platforms.

00:31:27

This is just a smattering, but what I'm giving you here is really important to know. The reference version of Python-- the one that's available at python.org-- is actually technically called CPython. And the reason for the C, as you can probably surmise, is that the Python interpreter is itself built in the C language.

00:31:47

Now this isn't the only variant of Python you can use by any means. This is simply the one that's officially supported by the Foundation, and the one that we're going to use in this training. Now what if, for instance, you want to run your Python code in a Java environment?

00:32:03

In some ways, Java is more flexible than Python. If you think Python is flexible, Java's even more so. We have an implementation of the Python interpreter called Jython that allows you to code in Python, but then port your code and run it, with a minimum of muss, fuss, or greasy aftertaste, in the JVM, or Java Virtual Machine.

00:32:24

So that should open up some huge opportunities and vistas, if you pursue the Jython solution. Now those of you who are in a .NET shop, well, you're working with those technologies, right? All of the Microsoft .NET stuff. The ASP .NET, their analog to PHP, that's their web development language.

00:32:43

You have C# and Visual Basic .NET, and those specific languages that all collapse upon the common framework, in Microsoft land, called-- you got it-- the .NET framework. The good news is, by using the IronPython implementation, you can code in Python and run your stuff in Microsoft environments.

00:33:03

In particular, I'd suggest you check out the site trypython.org. This gives an example of the integration of using IronPython to actually embed the Python interpreter, the interactive interpreter, in a Microsoft Silverlight object. In a nutshell, Microsoft Silverlight is Microsoft's answer to Adobe Flash.

00:33:24

It's primarily a web-based media display and interactive media platform. It's really quite cool. And then finally, although as I said, this list is by no means complete, we have the 2 to 3 libraries. And 2 to 3 is, as you probably can put together by now-- maybe not, maybe it's a bit too early-- this is what you would use the port your Python 2.x code to Python 3.x.

00:33:48

Remember, the key here with Python is flexibility, and it's just a question of figuring out which library you need, which tool you need, and once you do that, you're off and running in accomplishing your solution development goals. But wait, there's more.

00:34:02

I want to give you another slide of some really cool problem domains, or application domains, that we can address, or interact with, using Python. Remember that Guido van Rossum originally invented Python as a more convenient and flexible and user friendly way to perform systems administration and systems automation.

00:34:23

I have quite a bit of experience, for instance, as a Windows systems administrator. Likewise, I've used, say, VBScript and Windows PowerShell quite a lot-- more VBScript, actually-- in automating routine tasks, like creating a whole bunch of user accounts at once by making drive mappings, and web service calls, and so forth.

00:34:43

Well, we can do all that stuff with Python, and more. And we can do it cross-platform. Speaking of systems administration, you have-- or we have, I should say-- libraries available for just about every major database, whether it's Microsoft SQL Server, or Oracle, or in the open-source world, MySQL.

00:35:01

That's a big one. You can plug in, using these what are called APIs, or Application Programming Interfaces, to deal with network access, or to even go out onto the web-- open up web pages, fetch web content. You'll find, actually, that in the hacking world, if you're interested in ethical hacking and penetration testing, that Python is a very popular language for developing script files to accomplish some of these hacking or penetration-related tasks.

00:35:30

Python is not simply a console or command-line interface by any means. We have lots and lots of libraries, one of which, called TkInter, is bundled with the Python interpreter. But there's plenty more to choose from that support graphical user interface development.

00:35:47

There seems to be, in particular, a hardy market among folks to develop Python-based games, for instance. You'll find that Python is used in academia, not only to teach, but also in higher education research, and also in the science and math fields in general.

00:36:04

Python, with appropriate libraries installed, can do some serious number crunching to help those scientists and mathematicians and researchers to do their work. And then finally, although this again is not a comprehensive list, many large organizations, including Hewlett-Packard, for instance, will use Python to create scripts to automate hardware/software testing.

00:36:27

Let me further open your eyes now by giving you some examples of high-profile Python-based applications and organizations that use Python exclusively, or at least to a considerable degree. Probably the two highest-profile applications, one being a desktop application-- that's the original BitTorrent client, written in Python-- and somewhat surprisingly, perhaps, Google's YouTube.com, one of my favorite sites, involves a tremendous amount of Python behind it.

00:36:57

Google itself actually employees Guido van Rossum, so I hope it's of no surprise to you at all that a lot of Google's infrastructure relies upon Python. They have a wonderful service, called App Engine, that you can sign up to for free, and they will host your web applications for you.

00:37:15

It's a great platform for testing and initially rolling out your web apps, and sure enough, one of the supported languages and interfaces is Python. For those of you who are into sites like Digg, and other social media community-based sites, there's reddit.com.

00:37:31

I've read some very interesting things there, to say the least. They involve quite a bit of Python frameworking in their site. Pixar and Industrial Light and Magic, who bring some really amazing animation to the table with their films and their shorts, they use Python a great deal for their animation work.

00:37:48

In the math and science community, Los Alamos, NASA, Fermilab-- again, using Python all day long in doing their work. If you've ever used the SpamBayes open-source anti-spam mail plugin and mail application, that's a Python application. Trac is a popular bug tracking web application, relies upon Python.

00:38:08

And finally, the software updater Anaconda, that's used with Red Hat Linux and Fedora Linux, is also done in Python. We're going to close this admittedly fairly long introductory Nugget by answering the question, are there any downsides to Python? I mean, I've talked it up to the sky.

00:38:25

I hope that you're as excited to learn Python as I am to teach it, and that is significant, believe me. Well, the main downside that programmers will have with Python, although it's certainly less of a problem now than it has been in previous years, is that Python, because it's an interpreted language, tends to run at a slower speed than a fully compiled language.

00:38:45

You'll remember that the .py file, your source code file, gets ingested by the Python virtual machine in an intermediary format. It's brought down into what's called byte code. This is certainly not human readable code, but it's not just zeros and ones like machine language is.

00:39:01

So byte code is interpreted by the virtual hardware. Remember, the Python environment here, this virtual machine, is meant to abstract, or present kind of a silhouette, as it were, of the underlying hardware and operating system resources. That interpretation, by definition, is going to be slower than a fully compiled application that's already in machine language and is making calls directly to hardware.

00:39:25

Now what can we do to fix this? Because like I said, in 2010, at the time of this recording, this has never been less of a problem. Well, there's a library called Psyco. Interesting terminology here, right? You'll notice that with most open-source projects-- Python is certainly a good example-- you'll find that these geeks, of which I'm certainly one, get kind of creative with the names.

00:39:46

In fact, I haven't mentioned this yet, I'm surprised, but the word Python that Guido van Rossum coined is actually a direct allusion to Monty Python's Flying Circus, the British comedy troupe. So we're going to find some of that tongue-in-cheek humor as we go through the course.

00:40:03

Psyco is a module that is simply an accelerator. It's just-- its primary purpose in life is to make Python run faster, and some folks swear by it. They say they see triple digit, over 100 percent speed increases. Within the Python virtual machine itself, you'll find that it caches-- especially during development, when you're running the script over and over and over again-- that the Python virtual machine will cache code that's not changing during each run, and keep that code, those pieces of code, in the byte code format, such that when you re-run the script, a lot of the script-- at least the stuff that's not dynamic-- is already in byte code format.

00:40:43

And so that's going to improve the performance of the Python script also. The other downside-- and it's not exactly a downside, it's more of a challenge. And that is the challenge of running Python in a browser. Now you don't have the transparent browser friendliness in Python that you do with other languages, like JavaScript, for instance.

00:41:02

Because, remember, we have to rely upon the Java Virtual Machine, but there are definitely ways around this. One is to use Python with server-side scripting, using a protocol or an application programming interface called the Common Gateway Interface.

00:41:17

This has been tried and true technology for server-side scripting. More commonly, though, the way folks use Python with web applications is that they'll use a framework that wraps Python, and enables you to generate web content. Perhaps the most popular one now is called Django, again an illusion here, to Django Reinhardt, if you've ever listened to him.

00:41:37

I'm a guitarist myself, so I definitely vibe with this name. As previously mentioned, the Google App Engine is a web application framework that enables you to code in Python and render content in a browser. And the humorously named Pyjamas enables you to do AJAX, Asynchronous JavaScript And XML, by using Python as your language of choice.

00:42:00

So that wraps up our introductory Nugget. At this point, you should have a really clear idea of where we're going in the course. By the time we finish this course, I want you to be walking, jogging, and ready to run with your programming skills in Python.

00:42:15

You also should know exactly what you need in order to get started. Namely, you need to download and install Python, preferably version three, and you'll also want to grab the course files from nuggetlab.com. Finally, I hope you have a pretty good idea of some of the major benefits of Python, what the language is, difference between an interpreted language and a compiled language.

00:42:36

And most importantly, I hope you're excited to learn a whole lot of good stuff in this series. So let's put our thinking caps on and get to work. I hope that this has been informative for you, and I'd like to thank you for viewing.

Introduction to Python

Data Types, Part I

Data Types, Part II

Statements, Documentation, and Help

Strings, Revisited

Control Flow, Part I

Control Flow, Part II

Data Structures, Revisited

Functions

File Handling

Accessing the Network and Internet

Exception Handling

Modular Programming

Object-Oriented Programming

Advanced Topics

GUI Development

Python and Database Access

Porting Python Code

Python Frameworks and IDEs

Please help us improve by sharing your feedback on training courses and videos. For customer service questions, please contact our support team. The views expressed in comments reflect those of the author and not of CBT Nuggets. We reserve the right to remove comments that do not adhere to our community standards.

comments powered by Disqus
11 hrs 20 videos

COURSE RATING

Training Features


Practice Exams
These practice tests help you review your knowledge and prepare you for exams.

Virtual Lab
Use a virtual environment to reinforce what you are learning and get hands-on experience.

Offline Training
Our iOS and Android mobile apps offer the ability to download videos and train anytime, anywhere offline.

Accountability Coaching
Develop and maintain a study plan with one-to-one assistance from coaches.

Supplemental Files
Files/materials that supplement the video training.

Speed Control
Play videos at a faster or slower pace.

Bookmarks
Included in this course
Pick up where you left off watching a video.

Notes
Included in this course
Jot down information to refer back to at a later time.

Closed Captions
Follow what the trainers are saying with ease.