python创建文件时去掉非法字符的方法
作者:bibibabibobi k 时间:2023-10-12 02:15:51
windows系统中文件名不能包含 \ / : * ? " < > |想要创建必须过滤掉这些字符
def setFileTitle(self,title):
fileName = re.sub('[\/:*?"<>|]','-',title)#去掉非法字符
self.file = open(fileName + ".txt","w+")
利用正则去掉非法的字符。
来源:https://blog.csdn.net/u011444756/article/details/78311028
标签:python,非法,字符
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python3爬虫里关于代理的设置总结
2021-05-05 23:58:12
一步步教你编写可测试的Go语言代码
2024-04-29 13:03:43
python实现selenium网络爬虫的方法小结
2023-01-13 03:43:38
![](https://img.aspxhome.com/file/2023/9/128199_0s.png)
Python快速生成随机密码超简单实现
2022-08-07 19:26:09
![](https://img.aspxhome.com/file/2023/3/77923_0s.png)
python3.7中安装paddleocr及paddlepaddle包的多种方法
2022-08-11 00:00:57
![](https://img.aspxhome.com/file/2023/5/70775_0s.png)
SQL Server 2008 清空删除日志文件(瞬间日志变几M)
2024-01-21 13:06:47
SQL Server的FileStream和FileTable深入剖析
2023-07-17 01:17:24
![](https://img.aspxhome.com/file/UploadPic/201211/30/20121130203621460s.jpg)
Python使用sorted对字典的key或value排序
2023-12-12 06:36:53
快速排序的算法思想及Python版快速排序的实现示例
2021-10-26 18:04:24
python利用7z批量解压rar的实现
2021-05-02 18:58:31
Firefox window.close()的使用注意事项
2024-04-17 10:11:12
教你用Python pygame设置窗口标题和图标
2023-01-21 08:04:22
![](https://img.aspxhome.com/file/2023/0/133370_0s.png)
不需要用到正则的Python文本解析库parse
2022-11-08 17:28:09
![](https://img.aspxhome.com/file/2023/5/112405_0s.jpg)
在python中list作函数形参,防止被实参修改的实现方法
2022-11-15 19:27:25
![](https://img.aspxhome.com/file/2023/7/87777_0s.jpg)
Python ArgumentParse的subparser用法说明
2022-08-15 08:41:02
Python二叉搜索树与双向链表转换实现方法
2022-08-23 12:46:34
PHP实现HTML页面静态化的方法
2023-10-15 04:09:59
![](https://img.aspxhome.com/file/2023/3/72683_0s.png)
Mysql树形递归查询的实现方法
2024-01-14 08:05:16
vue实现二维码扫码功能(带样式)
2024-04-10 10:31:39
![](https://img.aspxhome.com/file/2023/2/139772_0s.png)
MySQL中or语句用法示例
2024-01-17 17:21:46