import string
filepath = '/a/b/cja#!$Y^%vfjb()&(-ew.)' # 这个文件名不可用
pathname = os.path.dirname(filepath)
basename = os.path.basename(filepath)
punctuation = string.punctuation + " "
punctuation = punctuation.replace(".", '')
for c in punctuation:
basename = basename.replace(c, "_")
filename = os.path.join(pathname, basename)