Python@TW: 會眾| IRC| Planet| 郵件列表| 聯絡我們

shlex 是 CPython 內建的 module ,是一個簡單的 lexical analyzer ,可以用來分析類似 UNIX shell 的 token 。例如有一字串「 ab 'de fg' hi 」,要如何 split 成 ['ab', 'de fg', 'hi'] ,而非 ['ab', '\'de', 'fg\' ', 'hi'] ?

   1 import shlex
   2 shlex.split('ab \'de fg\' hi')

CategoryCookbook

shlex (上次是 localhost 在 2009-04-01 04:14:21 編輯的)