contentreplace glob first argument.
This commit is contained in:
parent
6a8a687288
commit
852504be13
1 changed files with 24 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
|||
import glob
|
||||
import codecs
|
||||
import sys
|
||||
filename = sys.argv[1]
|
||||
filenames = glob.glob(sys.argv[1])
|
||||
replace_from = sys.argv[2]
|
||||
replace_to = sys.argv[3]
|
||||
try:
|
||||
|
@ -11,16 +12,17 @@ except IndexError:
|
|||
replace_from = codecs.decode(replace_from, 'unicode_escape')
|
||||
replace_to = codecs.decode(replace_to, 'unicode_escape')
|
||||
|
||||
def contentreplace(filename):
|
||||
f = open(filename, 'r', encoding='utf-8')
|
||||
with f:
|
||||
content = f.read()
|
||||
|
||||
occurances = content.count(replace_from)
|
||||
if occurances == 0:
|
||||
print('No occurances')
|
||||
exit()
|
||||
print('No occurences')
|
||||
return
|
||||
|
||||
print('Found %d occurances.' % occurances)
|
||||
print('Found %d occurences.' % occurances)
|
||||
if automatic:
|
||||
permission = 'y'
|
||||
else:
|
||||
|
@ -33,3 +35,6 @@ content = content.replace(replace_from, replace_to)
|
|||
f = open(filename, 'w', encoding='utf-8')
|
||||
with f:
|
||||
f.write(content)
|
||||
|
||||
for filename in filenames:
|
||||
contentreplace(filename)
|
||||
|
|
Loading…
Reference in a new issue