Skip to content

Commit 3503b15

Browse files
committed
Added option to overwrite input file
1 parent 7476a69 commit 3503b15

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

nicedoc/camel_to_snake.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ def Main():
3737
argv = sys.argv
3838
argc = len(argv)
3939

40-
if argc != 2:
41-
print(f"Usage: {argv[0]} <py-file>")
40+
if argc < 2 or argc > 3:
41+
print(f"Usage: {argv[0]} <py-file> [overwrite-flag=1/0]")
4242
quit()
4343

44+
overwrite_flag = False
45+
if argc > 2 and argv[2] == '1':
46+
overwrite_flag = True
47+
4448
filename = argv[1]
45-
with open(filename, 'r') as fp:
49+
with open(filename, 'r+') as fp:
4650
data = fp.read()
4751

4852
start = time.time()
@@ -51,8 +55,13 @@ def Main():
5155

5256
print(end - start)
5357

54-
with open(f"{filename}.out", 'w') as fp_out:
55-
fp_out.write(new_data)
58+
if overwrite_flag:
59+
outfile = filename
60+
else:
61+
outfile = f"{filename}.out"
62+
with open(outfile, 'w') as fp_out:
63+
fp_out.write(new_data)
64+
print(f"Successfully wrote new data into {outfile}")
5665

5766

5867
if __name__ == '__main__':

0 commit comments

Comments
 (0)