I want to create a function, read in a txt file, remove leading space and trailing space for each line, then write to a file, default to overwrite the file I read in, but with option to write to a new file.
Here is my code.

```
def cleanfile(inputfile, outputfile = inputfile):
    file1 = open(inputfile,'r')
    file2 = open(outputfile, 'w')
    lines = list(file1)
    newlines = map(lambda x: x.strip(), lines)
    newlines = list(newlines)
    for i in range(len(newlines)):
        file2.write(newlines[i] + '\n')
    file1.close()
    file2.close()    
cleanfile('hw.txt',)
cleanfile('hw.txt','hw_2.txt')

```

But it give me error. NameError: name 'inputfile' is not defined

How to solve this problem and achieve my goal please? Thank you very much.