Stripping leading tab of each line from a file I've got this Python code:

import os, re

def clnFile(file):
    inputFile = open(file, 'r')
    filename = file + '.tmp'
    outputFile = open(filename, 'w')
    code = inputFile.read()
    pattern = re.compile('\n\t')
    code = pattern.sub('\n', code)
    outputFile.write(code)
    inputFile.close()
    outputFile.close()
    os.remove(file)
    os.rename(filename, file)


It supposed to change content of the file. 
My algorithm is:


open original file
open original temporary file
read original file content to a string
change the string
write string to original temporary file
close original file
close temporary file
remove old original file
rename temporary file


I am sure there should be a way to simplify this code. Because now it's rather bulky.
Could anyone help me to adjust it?
You can use a different approach here:


Open file in r+ mode, it allows us to read as well as write the file along with truncation.
Read the content first and store it in a variable.
Seek back to 0th position using file.seek(0).
Truncate the file using file.truncate(), i.e it will truncate it to 0 bytes.
Now write the new content to the file object.


Code:

def clean_file(filename):
    with open(filename, 'r+') as f:
        content = f.read()
        f.seek(0)
        f.truncate()
        f.write(content.replace('\n\t', '\n'))


Few other points:


Prefer variable names with underscores in Python.
Always open files using the with statement in Python.
You can change the variable name file to filename to make it clearer to the user, otherwise it's hard to tell whether the file object expects a file name or file object.
Instead of using regex simply use the str.replace method.
To modify a file line by line in-place you can look into fileinput module.