added context guard in save_coord

Commit
976006fbe5f0a141af1041510a640a8e71a79150
Author
Marius Peter <blendoit@gmail.com>
Author date
Committer
Marius Peter <blendoit@gmail.com>
Committer date
Changed files
creator.py
index c6cae4ee..35784a8c 100644..100644
@@ -85,16 +85,19 @@
85 85 # print('\n')
86 86 return None
87 87
88 Removed: def save_coord(self, save_dir_path):
88 Added: def save_coord(self, save_dir_path, number):
89 89 """
90 90 Save all the object's coordinates (must be full path).
91 91 """
92 92
93 Removed: file_name = str(self)
94 Removed: full_path = os.path.join(save_dir_path, file_name + '.txt')
95 Removed: file = open(full_path, 'w')
96 Removed: sys.stdout = file
97 Removed: self.print_coord(4)
93 Added: file_name = '{}_{}.txt'.format(self, number)
94 Added: full_path = os.path.join(save_dir_path, file_name)
95 Added: # sys.stdout = open(full_path, 'w')
96 Added: # self.print_coord(2)
97 Added: with open(full_path, 'w') as sys.stdout:
98 Added: self.print_coord(2)
99 Added: # It is cleaner to use this context guard to ensure file is closed
100 Added:
98 101 return None
99 102
100 103 def pack_coord(self):
main.py
index a2dbd94a..5d2e90ab 100644..100644
@@ -21,7 +21,7 @@
21 21 import time
22 22 start_time = time.time()
23 23
24 Removed: CHORD_LENGTH = 1000
24 Added: CHORD_LENGTH = 100
25 25 SEMI_SPAN = 200
26 26
27 27 POP_SIZE = 1
@@ -58,9 +58,9 @@
58 58 creator.plot(af, af.spar, af.stringer)
59 59
60 60 # Save component coordinates
61 Removed: af.save_coord(SAVE_PATH)
62 Removed: af.spar.save_coord(SAVE_PATH)
63 Removed: af.stringer.save_coord(SAVE_PATH)
61 Added: af.save_coord(SAVE_PATH, _)
62 Added: af.spar.save_coord(SAVE_PATH, _)
63 Added: af.stringer.save_coord(SAVE_PATH, _)
64 64
65 65 # Print final execution time
66 66 print("--- %s seconds ---" % (time.time() - start_time))