cico98
V2EX  ›  Python

to_csv(f'{self.output_dir}/{row["code"]}.{row["code_name"]}.csv', index=False)这里面的 code_name 中包含*这里报错要怎么处理啊。

By cico98 at 2020 年 5 月 18 日 · 3301 次点击
4 条回复  •  2020-05-18 23:50:22 +08:00
renmu
   1
renmu  
   2020 年 5 月 18 日 via Android
不能做文件名的符号用个函数都过滤掉就好了
customsshen
   2
customsshen  
   2020 年 5 月 18 日
随便整一个相对路径文件名不行吗?
ClericPy
   3
ClericPy  
   2020 年 5 月 18 日
我直接无脑 re.sub(r'[^ \w]+', '_', name).strip() 替换了... 懒得去对比不同操作系统的安全文件名符号列表
Trim21
   4
Trim21  
   2020 年 5 月 18 日 via Android
那就用 replace 把星号删掉啊
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
© 2026 V2EX · 37ms · 3.9.8.5