3 ms·
That ignores how python scoping works. Built-ins are actually the last thing python checks. You can override the built-ins by re-defining the symbol in any of:
by ByteJockey 5y ago
That ignores how python scoping works. Built-ins are actually the last thing python checks.
You can override the built-ins by re-defining the symbol in any of: local functions, enclosing functions, or the global scope and it will impact the entirety of that scope.
- pwdisswordfish8 5y agoYou missed the point. It’s not about names themselves. What happens if I want to lookup bytestring-named attributes on a class defined in a Unicode-string module or vice versa?
- ByteJockey 5y agoAhh, the wording screwed me up. If I'm understanding your comment correctly this time, it would look something like: getattr(thing, b'attribute_name')
- im3w1l 5y agoI guess you could make it work as long as everything is ascii right? And if it's not then raise exception.
- ByteJockey 5y agoIf it's not ascii, you would just do: getattr(thing, u'attribute_with_unicode_characters') This would work in both python 2.7 and 3.9 (probably works with other 3.X versions but it's the one I actually tried).