是否有一个内置函数可以从字符串中删除所有不能在Windows文件名中使用的字符,或以某种方式替换它们? 例如:function("Some:unicode\symbols") --> "Some-unicode-symbols"
import re arbitrary_string = "File!name?.txt" cleaned_up_filename = re.sub(r'[/\\:*?"<>|]', '', arbitrary_string) filepath = os.path.join("/tmp", cleaned_up_filename) with open(filepath, 'wb') as f: # ... 从用户gx获取 显然要根据您的情况进行调整。