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)
| 2552 | ###################################################################### |
| 2553 | |
| 2554 | def 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 | """ |
no test coverage detected