I am copying files from one folder into another. The files contain dashes '-' and spaces ' ' . For example, test-file 123.dwg I need to replace those hyphens and spaces with underscores so it would look like this test_file_123.dwg
I've tried this and it replaces the hyphen fine but no the space. If I comment out the one of them, the other works.
file = string.replace(NAME,"-", "_")
file = string.replace(NAME," ", "_")
I have also tried this:
test = (' ', '-')
file = string.replace(NAME, test, "_")
but no luck.
I am using Python 2.7.
All tips welcome.
file. The second also replaces and also stores the result infile. At that point it overwrites the previous contents of the variable. No surprise there;x = 1followed byx = 2yields inx = 2, notx = 1 or 2 or any other previous value.