> Or, alternatively, you use 'six' (or a similar compatibility module) > and ensure unicode at runtime, using native or binary strings > otherwise: > > ---------- > from six import u > foo = u("this is a Unicode string in both Python 2.x and 3.x") > bar = "this is an 8-bit string in Python 2.x and a Unicode string in 3.x" > baz = b"this is an 8-bit string in Python 2.x and a bytes object in 3.x" > ---------- An alternative here is to use a function for bar, not foo: from __future__ import unicode_literals from six.next import native_str foo = "this is a Unicode string in both Python 2.x and 3.x" bar = native_str("this is an 7-bit string in Python 2.x" " and a Unicode string in 3.x") baz = b"this is an 8-bit string in Python 2.x and a bytes object in 3.x" Which of them is "better" depends on which of the two string types are more common. Regards, Martin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4