Skip to content
Snippets Groups Projects
Commit c8ff9a1b authored by jcandrsn's avatar jcandrsn
Browse files

Utility function for generating comment free code files that are shown in the thesis document.

parent 4a84fdf8
No related branches found
No related tags found
3 merge requests!5Master,!4Development,!3Development
import os
def matlab_comment_strip(filepath):
comment_free_code = ""
with open(filepath, 'r') as f:
for line in f:
keep = ''
comment_split = line.split('%')
if len(comment_split) > 1 and comment_split[0].strip() != "":
# Handles in line comments
keep = comment_split[0] +'\n'
elif len(comment_split) == 1:
keep = comment_split[0]
comment_free_code += keep
path, name = os.path.split(filepath)
name, ext = os.path.splitext(name)
new_path = os.path.join(path, 'no_comment_for_thesis', name + '_no_comment' + ext)
with open(new_path, 'w') as f:
f.write(comment_free_code)
if __name__ == "__main__":
for filename in os.listdir('.'):
name, ext = os.path.splitext(filename)
if ext == '.m':
matlab_comment_strip(filename)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment