if c == '':
    return
sys.stdout.write('{')
while True:
    c = mesh.read(8192)
if c == '':
    return
c = re.sub('\\[', ',{', c)
c = re.sub('\\]', '}', c)
sys.stdout.write(c)
if __name__ == '__main__':
    process_file(sys.argv[1])
Python - Opening and changing large text files