网络编程
位置:首页>> 网络编程>> Python编程>> python创建文件时去掉非法字符的方法

python创建文件时去掉非法字符的方法

作者:bibibabibobi k  发布时间:2023-10-12 02:15:51 

标签:python,非法,字符

windows系统中文件名不能包含 \ / : * ? " < > |想要创建必须过滤掉这些字符


def setFileTitle(self,title):
  fileName = re.sub('[\/:*?"<>|]','-',title)#去掉非法字符
  self.file = open(fileName + ".txt","w+")

利用正则去掉非法的字符。

来源:https://blog.csdn.net/u011444756/article/details/78311028

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com