File tree 1 file changed +14
-5
lines changed
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -37,12 +37,16 @@ def Main():
37
37
argv = sys .argv
38
38
argc = len (argv )
39
39
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] " )
42
42
quit ()
43
43
44
+ overwrite_flag = False
45
+ if argc > 2 and argv [2 ] == '1' :
46
+ overwrite_flag = True
47
+
44
48
filename = argv [1 ]
45
- with open (filename , 'r' ) as fp :
49
+ with open (filename , 'r+ ' ) as fp :
46
50
data = fp .read ()
47
51
48
52
start = time .time ()
@@ -51,8 +55,13 @@ def Main():
51
55
52
56
print (end - start )
53
57
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 } " )
56
65
57
66
58
67
if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments