Re: [問題] translate的問題

看板Python作者 (H-H-H-H-H-H-H-H-H-H-H-H)時間11年前 (2013/07/06 21:31), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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

07/07 00:30, , 1F
謝囉:)
07/07 00:30, 1F
文章代碼(AID): #1Hs1mUAr (Python)
討論串 (同標題文章)
文章代碼(AID): #1Hs1mUAr (Python)