Advertisement
turbo6412

file operation append

Sep 19th, 2021
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # main.py
  2.  
  3. def main():
  4.     separator = {'(': 'separator', ')': 'separator',
  5.                  ';': 'separator', '%%': 'separator'}
  6.  
  7.     val = input("Enter filename: ")
  8.  
  9.     fileName = val
  10.     sourceCodeFile = open(fileName, encoding='utf-8')
  11.  
  12.     for line in sourceCodeFile:
  13.         line_stripped = line.strip()
  14.  
  15.         outputFile = open("output_test1.txt", "a")
  16.  
  17.         if line_stripped in separator:
  18.             outputFile.write(
  19.                 f"{ separator[line_stripped] }  : {line_stripped} \n")
  20.  
  21.     sourceCodeFile.close()
  22.     outputFile.close()
  23.  
  24.  
  25. if __name__ == "__main__":
  26.     main()
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement