Created
August 27, 2012 09:23
-
-
Save imom0/3486877 to your computer and use it in GitHub Desktop.
Ellipsis in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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