MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / script_from_examples

Function script_from_examples

tools/python-3.11.9-amd64/Lib/doctest.py:2554–2634  ·  view source on GitHub ↗

r"""Extract script from text with examples. Converts text with examples to a Python script. Example input is converted to regular code. Example output and all other words are converted to comments: >>> text = ''' ... Here are examples of simple mat

(s)

Source from the content-addressed store, hash-verified

2552######################################################################
2553
2554def script_from_examples(s):
2555 r"""Extract script from text with examples.
2556
2557 Converts text with examples to a Python script. Example input is
2558 converted to regular code. Example output and all other words
2559 are converted to comments:
2560
2561 >>> text = '''
2562 ... Here are examples of simple math.
2563 ...
2564 ... Python has super accurate integer addition
2565 ...
2566 ... >>> 2 + 2
2567 ... 5
2568 ...
2569 ... And very friendly error messages:
2570 ...
2571 ... >>> 1/0
2572 ... To Infinity
2573 ... And
2574 ... Beyond
2575 ...
2576 ... You can use logic if you want:
2577 ...
2578 ... >>> if 0:
2579 ... ... blah
2580 ... ... blah
2581 ... ...
2582 ...
2583 ... Ho hum
2584 ... '''
2585
2586 >>> print(script_from_examples(text))
2587 # Here are examples of simple math.
2588 #
2589 # Python has super accurate integer addition
2590 #
2591 2 + 2
2592 # Expected:
2593 ## 5
2594 #
2595 # And very friendly error messages:
2596 #
2597 1/0
2598 # Expected:
2599 ## To Infinity
2600 ## And
2601 ## Beyond
2602 #
2603 # You can use logic if you want:
2604 #
2605 if 0:
2606 blah
2607 blah
2608 #
2609 # Ho hum
2610 <BLANKLINE>
2611 """

Callers 2

testsourceFunction · 0.85
debug_srcFunction · 0.85

Calls 7

DocTestParserClass · 0.85
_comment_lineFunction · 0.85
parseMethod · 0.45
appendMethod · 0.45
splitMethod · 0.45
popMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected