Dec-16-2017, 06:28 PM
Reading data from four files line by line sounds cool. This remind me to look into contextlib.
Example without modification of data:
Example without modification of data:
import contextlib import sys def read_files_iterative(filenames): with contextlib.ExitStack() as stack: try: files = [stack.enter_context(open(fname)) for fname in filenames] except (FileNotFoundError, PermissionError) as e: print(e, file=sys.stderr) raise for data in zip(*files): yield data def main(): if len(sys.argv) != 5: print('4 Filenames are required') return 1 filenames = sys.argv[1:5] try: for row in read_files_iterative(filenames): print(row) except: return 2 # putting them into a list: # content = list(read_files_iterative(filenames)) # print(content) return 0 if __name__ == '__main__': # be a nice shell citizen and return an error code sys.exit(main())Conclusion: This code won't help you and it does not fit to your professors requirements.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!