I would like to write some scripts in python that do some automated changes to source code. If the script determines it needs to change the file I would like to first check it out of perforce. I don't care about checking in because I will always want to build and test first.
Building from p4python source requires downloading and extracting the p4 api recommended for that version. For example, if building the Windows XP x86 version of P4Python 2008.2 for activepython 2.5:

download and extract both the p4python and p4api
fixup the setup.cfg for p4python to
point to the p4api directory.

To open files for edit (do a checkout), on the command line, see 'p4 help open'.
You can check out files without making a changelist if you add the file to the default changelist, but it's a good idea to make a changelist first.
P4Python doesn't currently compile for activepython 2.6 without visual studio 2008; the provided libs are built with 2005 or 2003. Forcing p4python to build against mingw is nearly impossible, even with pexports of python26.dll and reimp/reassembly of the provided .lib files into .a files.
In that case, you'll probably rather use subprocess, and return p4 results as marshalled python objects. You can write your own command wrapper that takes an arg array, constructs and runs the commands, and returns the results dictionary.
You might try changing everything, testing, and on success, opening the files that are different with something equivalent to 'p4 diff -se //...'
How do I check out a file from perforce in python?