Feb. 13, 2012
4:50 a.m.
Masklinn writes:
Why not open the file in binary mode in stead? (and replace `'*'` by `b'*'` in the startswith call)
This will often work, but it's task-dependent. In particular, I believe not just `.startswith(), but general regexps work with either bytes or str in Python 3. But other APIs may not. and you're going to need to prefix *all* literals (including those in modules your code imports!) with `b`. So you import a module that does exactly what you want, and be stymied by a TypeError because the module wants Unicode. This would not happen with Python 2, and there's the rub.