def fix_file(file_name, line_ranges, options=None, in_place=False,<EOL>diff=False, verbose=<NUM_LIT:0>, cwd=None):
import codecs<EOL>from os import getcwd<EOL>from pep8radius.diff import get_diff<EOL>from pep8radius.shell import from_dir<EOL>if cwd is None:<EOL><INDENT>cwd = getcwd()<EOL><DEDENT>with from_dir(cwd):<EOL><INDENT>try:<EOL><INDENT>with codecs.open(file_name, '<STR_LIT:r>', encoding='<STR_LIT:utf-8>') as f:<EOL><INDENT>original = f.read()<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>fixed = fix_code(original, line_ranges, options, verbose=verbose)<EOL>if in_place:<EOL><INDENT>with from_dir(cwd):<EOL><INDENT>with codecs.open(file_name, '<STR_LIT:w>', encoding='<STR_LIT:utf-8>') as f:<EOL><INDENT>f.write(fixed)<EOL><DEDENT><DEDENT><DEDENT>return get_diff(original, fixed, file_name) if diff else fixed<EOL>
Calls fix_code on the source code from the passed in file over the given
    line_ranges.

    - If diff then this returns the udiff for the changes, otherwise
    returns the fixed code.
    - If in_place the changes are written to the file.