I'm trying to copy a file,
>>> originalFile = '/Users/alvinspivey/Documents/workspace/Image_PCA/spectra_text/HIS/jean paul test 1 - Copy (2)/bean-1-aa.txt'
>>> copyFile = os.system('cp '+originalFile+' '+NewTmpFile)
But must first replace the spaces and parenthesis before the open function will work:
/Users/alvinspivey/Documents/workspace/Image_PCA/spectra_text/HIS/jean\ paul\ test\ 1\ -\ Copy\ \(2\)/bean-1-aa.txt
spaces ' ' --> '\ ' parenthesis '(' --> '\(' etc.
Replacing the spaces work:
>>> originalFile = re.sub(r'\s',r'\ ', os.path.join(root,file))
but parenthesis return an error:
>>> originalFile = re.sub(r'(',r'\(', originalFile)
Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 151, in sub return _compile(pattern, flags).sub(repl, string, count) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 244, in _compile raise error, v # invalid expression sre_constants.error: unbalanced parenthesis
Am I replacing parenthesis correctly?
Also, when using re.escape() for this, the file is not returned correctly. So it is not an alternative.