[Python-3000] bytes regular expression?

Victor Stinner victor.stinner at haypocalc.com
Thu Aug 9 04:27:19 CEST 2007


Hi,

Since Python 3000 regular expressions are now Unicode by default, how can I 
use bytes regex? Very simplified example of my problem:
  import re
  print( re.sub("(.)", b"[\\1]", b'abc') )

This code fails with exception:
  File "(...)/py3k-struni/Lib/re.py", line 241, in _compile_repl
     p = _cache_repl.get(key)
  TypeError: unhashable type: 'bytes'

Does "frozen bytes type" (immutable) exist to be able to use a cache?

Victor Stinner aka haypo
http://hachoir.org/


More information about the Python-3000 mailing list