Python

From MaccabeWiki
Jump to: navigation, search

Python is an object-oriented, interpreted programming language.

It is a very flexible language, which makes it great for a wide variety of tasks and its interpreted nature makes it fun and easy to experiment with when you are learning to program.

Python can be obtained at Python.org and you should learn more about it if you are interested in learning to program, or picking up a new programming language. Then you can download it. Python comes with an interpreter called IDLE, which can easily get you started.

Learning Python

Once you have installed Python, launch IDLE.

Type:

print "Hello World!"

Then press Enter. Next try:

print('Hello World')

you can use double quotes too.

Now try:

1+1

And:

a = 1+1

Now:

a

See how easy it is!

Python has many loadable modules that let you do everything from cryptography, to web browsing. If you really want to get your feet wet, you should work through the Tutorial at the Python Documentation page. While you are there take the time to notice the Language Reference (how everything in Python works) and Library Reference (information about all the modules that come with Python.

Good programmers aren't afraid to spend a little time reading documentation!

IDLE is great for playing, but if you are serious about Python I'd suggest getting a better IDE (Integrated Development Environment). If you don't want to pay, get SPE (Stani's Python Editor). If you get really serious and don't mind a few dollars I hear that WingIDE is very nice. Before installing SPE, you need to download and install wxPython, a framework it uses first. PythonWin is another, more lightweight alternative.

In either SPE or PythonWin, you can hold control and press the Up arrow to retrieve past commands you've entered, an invaluable tool. Both also support tab completion.

Play around with the dir() and help() functions while you learn.

If you get beyond playing and make something, you can generate an standalone executable, so people don't have to install Python to run it, using py2exe, there is a tutorial for this and you may want to read a bit about Distutils before you do this.

If you want to get writing GUI applications, I suggest getting PyGTK, which if you use the nice all-in-one installer puts on everything you need--PyGObject, PyCairo, PyGTK. It also includes an excellent example Gtk-demo which demonstrates how to do most things and shows you the code to do them.

Things I've written in Python

Huffman Coding Module