Goal:
I want to write a program for this:
In a folder I have =n= number of files;
first read one file and perform some operation then store result in a separate file.
Then read 2nd file, perform operation again and save result in new 2nd file.
Do the same procedure for n number of files.
The program reads all files one by one and
stores results of each file separately.
solution:
#+BEGIN_SRC Python
import sys
#argv is your commandline arguments, argv[0] is your program name, so skip it
for n in sys.argv[1:]:
print(n) #print out the filename we are currently processing
input=open(n,”r”)
output=open(n,+”.out”,”w”)
# do some processing
input.close()
output.close()
#+END_SRC
– syn :: system-specific parameters and functions
– module :: a file contains Python code
why python module?
Python module is used to group related functions, classes, and variables
for better code management and avoiding name clash
https://stackoverflow.com/questions/208120/how-to-read-and-write-multiple-files
Similar Posts:
- Python: How to Batch Read the Form Information in Word and output them to Excel file
- [Solved] PythonTypeError: ‘<' not supported between instances of 'str' and 'int'
- [Solved] Python error: EOFError: Ran out of input
- Python3 urlopen() TypeError: can’t convert ‘bytes’ object to str im…
- AttributeError: ‘list’ object has no attribute ‘keys’
- [Solved] error C1090: PDB API call failed, error code ‘0’
- C# call Python error no module named OS [How to Solve]
- Python_:TypeError: write() argument must be str, not int
- Python ImportError: No module named win32com.client [How to Solve]