 This is kind of the outline of the stock. So as Eric said, we first going to do an introduction to Python itself. And then as your schedules will show you this, tomorrow we are going to look at numpy and scipy and then look at wrapping, which is how you interface Python to high performance languages like Fortran and C and C++. And then later on get on to other aspects like creating UIs, making applications, doing visualizations and things like that. So today is primarily going to be an introduction to Python itself. So those of you who are really good at Python just bear with me, hopefully you will just brush up your basics and the idea is so that all of us are on the same page tomorrow. So all of us have the baseline skills with Python. So I usually have a bunch of introductory slides on Python and then I go on to a tutorial, a full-fledged tutorial and this is largely based on the Python tutorial, which is a very nice document. I usually recommend anybody who is new to Python to just read the tutorial because it is very well written. It is written by the author of the language, by the man himself. So as Eric mentioned, Guido van Rossem is the creator of Python and he created it sometime in 1989. So the language has been around for quite a long time, 17 years. So it is not a new kid on the language block. And Guido himself has experience with building languages, he has a lot of experience with that. So it is built by people who really know their stuff and it has been around for a long while and that is a testament to the fact that it is a strong language. The name Python does not have anything to do with the reptile, it has something to do with the comedy series, Monty Python's Flying Circus, which was a hit, still good fun to watch. The current stable version of Python is 2.5, the nice thing about Python is it is free and it is free in the sense that it is BSD style, which means you can do anything you want with it pretty much without suing the person who developed it. Python is usually available as part of any sane GNU Linux distribution. So pretty much anywhere you should be able to find it, if not that distribution is not worth using. There is a lot of information on it on the web. So this is just general resources that you can look at and the documentation is particularly very good. The first time when I wanted to look at doing something scripting, I had the choice of using Perl because I wanted to do some text processing. And I looked at Python because of Red Hat's Anaconda, it goes to this Anaconda and there is some .py extension and I looked at it and it is a script. So I said hey, this looks, it looks readable, I think I can follow it, I had a C background. And then I decided okay, let me hunt for documentation and I could not find, this was long ago, so maybe I was not, there was not a Google around at the time. So I looked for Perl documentation, I did not really find something that was very good. And then I said hey, let me try Python, there was a tutorial, the tutorial actually got me started. So that made a huge difference. So free documentation is a big deal. There are lots of tutorials and I really recommend reading the tutorial, I will just show you a quick screenshot. This is the documentation that I have on my machine and this is pretty much how the Python documentation layout looks like. You have something like a tutorial, you start here and you always have something called what's new in Python. So the documentation is targeted to a particular version of Python and it's always worth looking at what's new because you know what's have changed from 2.4 to 2.5, 2.3 to 2.2 and so on and so forth. You have a module index, of course you don't need that anymore with Google. Probably the most important thing here is the library reference and as they say keep this under your pillow. So basically it's very useful if you want to say I want to do this, I want to process, I want to fetch data from a URL and you really don't know where to look. Best place is to just go into the library reference, search there and then you find that there's a module that just does what you want and you don't even have to install a package for it. So this is very, very handy and there's a bunch of other things like extending and embedding Python C API. So it's pretty much complete with respect to basic Python. This is really useful. I'm going to go through this very rapidly. In fact, the entire introduction to Python is going to be rapid. Hopefully during the lab sessions you'll have time to hone your skills. It's basically high level interpreted, modular and object oriented. I'm not going to explain more than what Eric has done already. It's very easy to learn, it's very easy to write code and it's very easy to read code which is very, very important. Because most of the time you learn language, you learn tricks by looking at how other people do it and this is how people learn languages per se. You learn by looking at what your parents say, same way you learn a lot by looking at somebody else's code and that code is readable, makes a huge difference. It offers a much faster development cycle in that basically you don't have a compile cycle and usually the slowest person developing the code is you, not the computer. The computer is much faster than you are. The problem is we take time to build algorithms. We take time to prototype things. We take time to think about things. And often with many other languages, you end up wrestling with the language. You're worrying about is this syntax right, is that syntax right? With Python, that's usually not a problem. So basically it allows for rapid application development. And one very, very important thing about Python is the interactive interpreter. So think of a shell. How many of you have used a shell? I guess most everybody has used a shell. So you type a command and it does something for you. And this is really extremely productive. And if you look at Matlab, as Eric was saying, the real power of this is that you can use it like a calculator. You can use it like, I just start up something, type something out, and I have my results right there. I don't have to sit, write it in an editor, compile it, handle stupid errors, rewrite the code, build it, and then get results that are wrong, and then go change that again. It's just too painful. It's much faster doing it straight off the bat. The second thing is you'll notice that your shell usually has a lot of powerful features. It's configurable, it's extendable, and when you type things, it actually gives you feedback. So you type tab, for example, it'll complete the name. It remembers history. Things like this are small things, but they make a huge difference. The other thing with a shell is usually you have access to help, like a man page or something like that. So if you have a shell that builds all of these pieces together, that gives you interactive abilities, that lets you use things, use yourself, be efficient, and also gives you access to help and things like that, it's extremely powerful. So often, I usually don't have, when I talk to students, I don't actually, I don't have a single book on Python with me. I program extensively with Python. I do have lots of C++ books. The reason I can do this is with Python, I just start up the interpreter and type. If I forget what is the syntax of this thing, I just go in there and type and it's done. Whereas with another language, it's bigger hassle, so I have to read a manual or a reference manual. So the interpreter is extremely useful. And hopefully, you'll see that across the course. And as Eric said, one of the big deals for scientific computing is that you can interface Python with C, C++ and Fortran libraries. Now this is important in two counts. Lots of libraries, if you look at library market share, there are a lot of libraries out there that are C or C++ based. And lots of native codes in the scientific computing community are basically written in Fortran. And it's very important that you be able to use these codes. If you can't, you basically lost somebody. Basically, he can't use your line. I always give this quote about Python again. This is a quote by the guy who created NumPy. Same as Travis Oliphant and he says, I came across Python and its numerical extension in 1998. I quickly fell in love, not the word love, with the language, which is a remarkable statement to make about a programming language. If I had not seen others with the same view, I might have seriously doubted my sanity. So it's not a view shared by one person. A lot of people have a lot of passion for the language. Okay, so why not MATLAB? So MATLAB does all of this, not quite, but several of these things. Firstly, it's open source and free. You don't have to pay anybody any license to do the stuff. All the stuff we're doing in this course is free and it's all BSD licensed. So basically, there are no restrictions on what you do, how you do, where you do it. It's portable. It's a real programming language. It's not a specifically tailored numeric language. And it's written by people who are computer scientists and it's used by people who are computer scientists. So which means the language itself is rich. It is a full-fledged language. You can do more than just array and math. You can wrap large C++ codes. You can build codes. Any of you used make files? Okay, so basically make files let you build codes. Let's say you have 100 C programs and you change one of them. You want automatically some tool to build that one change thing. So you have make files to do this. Make files are a bit of a pain because at least I keep forgetting the syntax all the time. I have to keep reading the info manual and figuring out what is the right syntax. Turns out that there's a tool called Scones which is written in Python. And so your make files are Python files. And it's very convenient, very easy to use thing which lets you build C++ large code bases. It has a very powerful interactive and data analysis plotting suite which is on par with MATLAB. Of course as with most open source projects several of these things are not as well documented as they should be but they're getting there. You can build parallel applications. I don't know if you can actually do that with MATLAB easily as with Python it's not that hard to do. The biggest advantage is it doesn't just stop with your scientific computing or your interactive explorations. Lot of my shell scripts, a lot of useful tools that I write are written in Python. So I wrote a job scheduler which basically lets me schedule thousands of runs on a cluster of Linux machines. And it was like an afternoon's work. Okay, maybe if you're not very experienced maybe a couple of days work. And it's a demon that runs on multiple machines and lets me schedule runs from anywhere and have them run whenever the computer can run it. It's a poor man scheduler but I was able to do it because of Python. So basically it's just not as if you just do this domain specific thing. You can actually do a heck of a lot more with Python. And that's very, very important. So the idea is if you learn one high performance language if you're doing scientific computing and you really want performance and you have a scripting language that's powerful like Python, you're set. That's the important thing. So why not Python? Why wouldn't you use it? If you want high performance as I said you may want sometimes to write something efficiently in a language like Fortran or C++ and Python lets you do that. So it's really not a big issue.