As others note, using Python’s Ellipsis object in slices is rather obscure, and there are hardly any good examples out there. So I thought I’d do my bit with a nice, simple example, complete with comments:
# Portable way to get the You-Know-Which object without naming it
class __:
def __getitem__(__, _):
return _
___ = __()[...]
# An Ellipsobinary-to-ASCII convertor
class __:
def __getitem__(__, _):
return chr(sum(1<<i if _[-i-1] is ___ else 0 for i in range(len(_))))
_ = __()
# Finally, use the That-Which-Must-Not-Be-Named object
print (
_[...,_,_,...,_,_,_] +
_[...,...,_,_,...,_,...] +
_[...,...,_,...,...,_,_] +
_[...,...,_,...,...,_,_] +
_[...,...,_,...,...,...,...] +
_[...,_,...,...,_,_] +
_[...,_,_,_,_,_] +
_[...,...,...,_,...,...,...] +
_[...,...,_,...,...,...,...] +
_[...,...,...,_,_,...,_] +
_[...,...,_,...,...,_,_] +
_[...,...,_,_,...,_,_] +
_[...,_,_,_,_,...])
And you thought Python code couldn’t be obfuscated?
Seriously, though … do any non-NumPy programmers actually use Ellipsis? I have yet to find other (non-NumPy) uses of it in the wild.
8 May 2009 by Ben 7 comments