看板 Python 關於我們 聯絡資訊
※ 引述《popular10347 (popular)》之銘言: : hi,我現在用的是python3.3 : 看了一本書example code,用來delete character : 以下是範例: : table=maketrans('cs','kz') : "this is an incredible test".translate(table,' ') : 想要再轉換character之後刪掉whitespace : 可是python 的command line 顯示: translate() takes exactly one argument(2 given : ) : 是哪裡出了問題? Python 3 以後使用 Unicode translate() 處理 Unicode 要用新的方式,最簡單的解決方法是改用 bytes Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> table=bytes.maketrans(b'cs',b'kz') >>> b"this is an incredible test".translate(table,b' ') b'thizizaninkredibletezt' -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.67.49.104
popular10347:謝囉:) 07/07 00:30