change file path

add fclose
translate C to Python

TODO: need more optimization!!!