How can we execute the commands on one file in a such a way that the results will get saved in another file?
Do we have any such built in method which we can use?

Look under shelve in Python help.

you can create a class to which opens a file write data and closes a file
just invoke in your script ,use same instance as long as u want results in same file,generate seperate instance for result file #2

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.