Possible to make custom string literal prefixes in Python?
Let's say I have a custom class derived from str that implements/overrides some methods: class mystr(str): # just an example for a custom method: def something(self): return "anything" Now currently I have to manually create instances of mystr by passing it a string in the constructor: ms1 = mystr("my string") s = "another string" ms2 = mystr(s) This is not too bad, but it lead to the idea that it would be cool to use a custom string prefix similar to b'bytes string' or r'raw string' or u'unicode string' . Is it somehow possible in Python to create/register such a custom string literal prefix