Can I have an ellipsis at the beginning of the line in a Python doctest?

前端 未结 4 2026
我寻月下人不归
我寻月下人不归 2021-01-17 09:37

Python doctests are cool. Let me start with a simple example:

def foo():
  \"\"\"
  >>> foo()
  hello world
  \"\"\"
  print \"hello world\"
         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 10:19

    Here is a somewhat simpler way to do this: Just print a dummy string before the line that begins with the unknown output.

    Like this:

    def foo():
      """
      >>> print 'ignore'; foo() # doctest: +ELLIPSIS
      ignore... world
      """
      print "hello world"
    

提交回复
热议问题