import os

# Move to the C:/foo directory
os.chdir('C:/foo')

# Create the file C:/foo/bar.txt and write
#'Hello world!' in it, then close it.
f = open('bar.txt', 'w')
f.write('Hello world!')
f.close()