Python idee


SUBMITTED BY: bitcoinsachen

DATE: Oct. 17, 2016, 4:23 p.m.

FORMAT: Python 3

SIZE: 1.4 kB

HITS: 927

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Oct 17 18:08:47 2016
  5. @author: tztz
  6. """
  7. #f = open("ga30_10.out","r") #opens file with name of "test.txt"
  8. #print(f.read(1))
  9. #print(f.read())
  10. #
  11. #schreibt eine Datei was
  12. with open("ga30_10.out") as infile, open("../was","w") as outfile:
  13. collector = []
  14. for line in infile:
  15. if line.startswith("tilt="):
  16. collector = []
  17. collector.append(line)
  18. if line.startswith("tilt="):
  19. for outline in collector:
  20. outfile.write(outline)
  21. #noch nicht getest
  22. whole_data = []
  23. grab_lines = False
  24. with open('input','r') as atom_file:
  25. molecule_data = ['23\n\n']
  26. for line in atom_file:
  27. if line.startswith('coordinates'):
  28. grab_lines = True
  29. continue
  30. elif line.startswith('velocities'):
  31. grab_lines = False
  32. if molecule_data:
  33. #just checks that we aren't appending an empty list.
  34. molecule_data.append('\n')
  35. whole_data.append(molecule_data)
  36. molecule_data = ['23\n\n']
  37. if grab_lines: #in python 'is True' is implicit for many types.
  38. molecule_data.append(line)
  39. with open('output','w') as out_file:
  40. for molecule in whole_data:
  41. out_file.write(''.join(molecule))

comments powered by Disqus