os.chdir
should do the correct thing. Here is some code used for testing on python REPL, assuming you have a ./test
dir in working dir.
>>> import os
>>> os.chdir('test')
>>> f = open('testfile', 'w')
>>> print>>f, 'hello world'
>>> f.close()
test/testfile
is now present with the right contents.