The problem of string substitution in python

    new_file = old_file.replace(" ", "-").replace(""", "").replace("" ", "").replace("(", "").replace(")","").replace(":", "-")

there are a lot of special characters when dealing with folders. Apart from this, is there an elegant way that I think is too ugly?

Mar.08,2022

you can do this:

  str.maketrans  mentioned in the document: 

  • the first two parameters establish an one-to-one mapping
  • the characters of the third parameter are mapped to ''
Menu