3 ms·
@ is a binary operator with the same precedence and left-right associativity as * , /, and //. It's hard to think of places where @ could be abused where those
by dalke 13y ago
@ is a binary operator with the same precedence and left-right associativity as * , /, and //. It's hard to think of places where @ could be abused where those other three couldn't equally well be a source of abuse. There hasn't been much abuse of those other three, so there likely won't be much abuse of @.
I think the only real (ab)use of @ is to echo its use in another language. For example, @ means something in XPath, so X@Y could be used as a short-hand for X.attrib[Y] in an ElementTree-like API:
tree = load_xml_tree(...)
for node in tree.select("//item[@price > 2*@discount]"):
print(node @ "price", node @ "discount")
- ecma 13y agoThe only other hypothetical I can think of right now is evaluation shorthand. Something like an expression group represented by a class which may be subject to arithmetic using standard operators. @ could be used as shorthand for a .evaluate_at() method but it's probably not that useful anyway. Maybe passing objects with 'argument @ resource' would be interesting...
- tveita 13y agoIn Python 3.4's pathlib, you can concatenate two paths by dividing one path with the other. I guess you could torture @ for similar purposes in an email library or something.
- Widdershin 13y agoJust got to say, dirtiness aside, overloading / to be path.join is actually a godsend for readability working with path heavy code.