Path looks like:
CLOUD_PATH = os.path.join(HOME, 'library', 'data')
WORKDIR = os.getcwd()
Then in script I have a function:
def urlchanger(src, dst):
xmlsdir = os.path.join(src, 'Plugins', '_xmls', '')
xmlfiles = [ f for f in os.listdir(xmlsdir) if re.match(r'^.*\.xml', f)]
for file in xmlfiles:
with open(os.path.join(xmlsdir, file), 'r+') as f:
indata = f.read()
if ('dontchange.me' in indata):
outdata = re.sub(r'http://dontchange.me/', dst, indata)
print 'Updating file %s:\n \n%s' % (os.path.join(xmlsdir, file), outdata)
with open((os.path.join(os.environ['TEMP'], file)), 'w') as n:
n.write(outdata)
Which called with:
urlchanger(WORKDIR, CLOUD_PATH)
Problem is, that re.sub performs substitution without trailing slash after data directory (result from out-file):
plugin assemblyUrl="C:\library\dataSomefile.dll"
Between data and Somefile - dataSomefile.
I tried add '' to CLOUD_PATH like:
CLOUD_PATH = os.path.join(HOME, 'library', 'data', '')
But got an error:
...
raise error, v # invalid expression
sre_constants.error: bogus escape (end of line)
And same for few other attempts...
P.S. Script reads data from source file, looks for dontchange.me, replaces it with given URL, and will write new new file. Python 2.7.