Skip to content

Instantly share code, notes, and snippets.

@imom0
Created August 27, 2012 09:23
Show Gist options
  • Save imom0/3486877 to your computer and use it in GitHub Desktop.
Save imom0/3486877 to your computer and use it in GitHub Desktop.
Ellipsis in python
class MyClass(object):
"""Example of a doctest Ellipsis
>>> thing = MyClass()
>>> # Match <class '__main__.MyClass'> and <class '%(module).MyClass'>
>>> type(thing) # doctest:+ELLIPSIS
<class '....MyClass'>
"""
pass
# placeholder
# http://stackoverflow.com/a/6189379/995394
>>> class TestEllipsis(object):
... def __getitem__(self, item):
... if item is Ellipsis:
... return "Returning all items"
... else:
... return "return %r items" % item
...
>>> x = TestEllipsis()
>>> print x[2]
return 2 items
>>> print x[...]
Returning all items
# http://stackoverflow.com/a/118395/995394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment