<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_file(fname_parts, content):
 """ write a file and create all needed directories """


    fname_parts = [str(part) for part in fname_parts]
    # try to create the directory
    if len(fname_parts) > 1:
        try:
            os.makedirs(os.path.join(*fname_parts[:-1]))
        except OSError:
            pass
    # write file
    fhandle = open(os.path.join(*fname_parts), "w")
    fhandle.write(content)
    fhandle.close()