Code readme

In order to make the code examples accessible to the widest possible audience I have written them using the Python 2 dialect. While I personally prefer Python 3, the older dialect is still more widely used and is the default in all the Linux distros I’ve used. I appear to be in a minority of people who prefer v3 although this is probably because I started on v3.1

For some of the examples I assume you have Python Win32 Extensions installed. Because of the frequency I will not explicitly mention this. It is easy to see the examples which use these extensions at they have an import win32* at the top. If the example use any other non-standard module or library this will be explicitly mentioned along with a homepage.

If you are not already, I recommend you install pip (a package manager) to add modules. This has been included with Python since v3.4 and recent v2.7 installs also include pip. Enter pip -V from the command to check if it is installed,

If you are missing pip, download the script and run it (or enter python from the command line). Full documentation for pip is available here. This will place pip.exe inside your Python installation’s Scripts folder. If this in not on your path you can run C:\PythonXX\Tools\Scripts\ to add it the path or change into C:\PythonXX\Scripts to run pip.

Once pip has been installed you can test this by installing virtualenv by simply entering pip install virtualenv, or even better pip install pipenv!

Where the code fragments require a change in order for them to run on Python 3 (apart from the print command) there will be a comment on the line before with the necessary change or a warning. For the example programs supplied you can use to convert them. Run python -w to make the changes. If you forget the -w it will not write the changes to the file and instead display them on the screen.

Talking of code I have attempted to keep with the recommendations in the PEP8 style guide with one noticeable exception for code fragments; multiple imports will be included on a single line. This is done to reduce space.

I have tried to test all example snippets and programs on 32bit Python 2.5, 64bit Python 2.7 and 64bit Python3.2 after running; if you spot any typos please let me know.

For several of the posts I have included an example program at the end to illustrate. I believe it would be distracting to include the code in the body of the post and then media options on WordPress do not cater for program code. As a result I have used BitBucket to host the program files. This allows each program to be viewed from the link and you can download an archive of all the current programs by clicking on the Get Source link.

I do recommend the use of Mercurial as a source control management tool. You can clone the entire repository straight from the BitBucket website; they even give you the command to do it. For Windows I use TortoiseHg which includes the command line tool and a GUI integrated into Windows explorer. There is even a manual if you have a couple of hours to learn.

Finally use the comments section if you think you’ve spotted a problem, want to ask a question or just generally leave a message. I try and regularly check the blog even if I don’t manage to post as often as I would like.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.