Skip to content

Commit

Permalink
Added argparser, filename can be provided throug command line
Browse files Browse the repository at this point in the history
  • Loading branch information
emes3ye committed Feb 11, 2020
1 parent 0a36d5c commit ded3728
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions change_image_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--filename', required = True)
def change_path(filename):
f = open(filename, 'r')
f1 = open('output.txt', 'w+')
Expand All @@ -11,5 +13,6 @@ def change_path(filename):
f1.close()

if __name__ == "__main__":
filename = 'test.txt'
change_path(filename)
args = parser.parse_args()
print(args.filename)
change_path(args.filename)
13 changes: 9 additions & 4 deletions shuffle_file_contents.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import random

import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('--filename', required = True)
class Shuffle:

def shuffle_file_elements(self, filepath, output_file_path):
def shuffle_file_elements(self, filepath):
with open(filepath, 'r') as f:
read_data = f.read()
items = read_data.split('\n')
random.shuffle(items)
with open(output_file_path, 'w') as output:
os.remove(filepath)
with open(filepath, 'w') as output:
for line in items:
output.write(line)
output.write('\n')

if __name__ == "__main__":
args = parser.parse_args()
shuffle_obj = Shuffle()
shuffle_obj.shuffle_file_elements('train_v0_3.txt', 'output_train_v0_3.txt')
shuffle_obj.shuffle_file_elements(args.filename)

0 comments on commit ded3728

Please sign in to comment.