-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Theodore Lindsay
committed
Apr 9, 2018
1 parent
0fd1571
commit 86ff386
Showing
2 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#utility functions for dealing with svg files. | ||
|
||
def replace_non_unique(in_filename,out_filename, | ||
search_string = 'text_to_replace', | ||
prefix = ''): | ||
"""parse the document 'in_filename' and replace all | ||
instances of the string 'search_string' with the | ||
unique string 'prefix_x' where x is the occurance | ||
of the search_string""" | ||
with open(in_filename,'rt') as inf: | ||
strdta = inf.read() | ||
n_instances = strdta.count(search_string) | ||
for i in range(n_instances): | ||
strdta = strdta.replace(search_string, prefix + '_%s'%(i), 1) | ||
with open(out_filename,'wt') as outf: | ||
outf.write(strdta) |