推荐学习书目
› 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
winneter
V2EX  ›  Python

报错, TypeError: translate() takes exactly one argument (2 given),需要怎么解决呢?

  •  
  •   winneter · Oct 1, 2016 · 6788 views
    This topic created in 3648 days ago, the information mentioned may be changed or developed.

    http://ww2.sinaimg.cn/large/69290310gw1f8ck5xv7qhj20fw07iwfa.jpg

    打开文件夹批量重名,一直出现这个问题,怎么处理呢?

    Supplement 1  ·  Oct 1, 2016
    自己去查了看下,有以下两种方法
    os.rename(file_name,file_name.translate(file_name.maketrans("0123456789", " ")))
    os.rename(file_name,file_name.lstrip("0123456789"))
    Supplement 2  ·  Oct 1, 2016
    the first two maketrans arguments must have equal length
    5 replies  •  2016-10-01 12:42:36 +08:00
    sadscv
        1
    sadscv  
       Oct 1, 2016 via Android
    字面意思就是第十行的 translate 函数只需要一个参数,而你给了它两个。
    winneter
        2
    winneter  
    OP
       Oct 1, 2016 via Android
    @sadscv 我不用 none 的时候,倒是不会报错,但是并没有文件重命名的效果
    aprikyblue
        4
    aprikyblue  
       Oct 1, 2016
    不是很懂 python ,看起来 python3 已经去掉了 deletechars 这个参数。。

    python2: str.translate(table[, deletechars])
    python3: str.translate(table)
    winneter
        5
    winneter  
    OP
       Oct 1, 2016
    @aprikyblue 只是我看视频上那个老师那么写的,发现报错了,以为是什么其他问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2704 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:50 · PVG 16:50 · LAX 01:50 · JFK 04:50
    ♥ Do have faith in what you're doing.