def prepend(line, path):
if isinstance(line, str):<EOL><INDENT>line = line.encode('<STR_LIT:utf-8>')<EOL><DEDENT>if not line.endswith(b'<STR_LIT:\n>'):<EOL><INDENT>line += b'<STR_LIT:\n>'<EOL><DEDENT>temp = tempfile.NamedTemporaryFile('<STR_LIT:wb>')<EOL>temp_name = temp.name <EOL>temp.close()<EOL>with open(temp_name, '<STR_LIT:wb>') as temp:<EOL><INDENT>temp.write(line)<EOL>with open(path, '<STR_LIT:rb>') as r:<EOL><INDENT>temp.write(r.read())<EOL><DEDENT><DEDENT>shutil.move(temp_name, path)<EOL>
Appends *line* to the _beginning_ of the file at the given *path*.

If *line* doesn't end in a newline one will be appended to the end of it.