Message 71615 - Python tracker
Selon STINNER Victor <report@bugs.python.org>: > IMHO, the best solution is to create such class: > > class Filename: > def __init__(self, orig): > self.as_bytes = orig > self.as_str = myformat(orig) > def __str__(self): > return self.as_str > def __bytes__(self): > return self.as_bytes I agree that logically it's the right solution. It's also the most invasive. If that class is made a subclass of str, however, existing code shouldn't break more than it currently does.