Code snippet below:

import os
tmp = os.path.abspath(__file__)
tmp = os.path.dirname(tmp)
os.chdir(tmp)