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 math.
(s)
| 2717 | ###################################################################### |
| 2718 | |
| 2719 | def script_from_examples(s): |
| 2720 | r"""Extract script from text with examples. |
| 2721 | |
| 2722 | Converts text with examples to a Python script. Example input is |
| 2723 | converted to regular code. Example output and all other words |
| 2724 | are converted to comments: |
| 2725 | |
| 2726 | >>> text = ''' |
| 2727 | ... Here are examples of simple math. |
| 2728 | ... |
| 2729 | ... Python has super accurate integer addition |
| 2730 | ... |
| 2731 | ... >>> 2 + 2 |
| 2732 | ... 5 |
| 2733 | ... |
| 2734 | ... And very friendly error messages: |
| 2735 | ... |
| 2736 | ... >>> 1/0 |
| 2737 | ... To Infinity |
| 2738 | ... And |
| 2739 | ... Beyond |
| 2740 | ... |
| 2741 | ... You can use logic if you want: |
| 2742 | ... |
| 2743 | ... >>> if 0: |
| 2744 | ... ... blah |
| 2745 | ... ... blah |
| 2746 | ... ... |
| 2747 | ... |
| 2748 | ... Ho hum |
| 2749 | ... ''' |
| 2750 | |
| 2751 | >>> print(script_from_examples(text)) |
| 2752 | # Here are examples of simple math. |
| 2753 | # |
| 2754 | # Python has super accurate integer addition |
| 2755 | # |
| 2756 | 2 + 2 |
| 2757 | # Expected: |
| 2758 | ## 5 |
| 2759 | # |
| 2760 | # And very friendly error messages: |
| 2761 | # |
| 2762 | 1/0 |
| 2763 | # Expected: |
| 2764 | ## To Infinity |
| 2765 | ## And |
| 2766 | ## Beyond |
| 2767 | # |
| 2768 | # You can use logic if you want: |
| 2769 | # |
| 2770 | if 0: |
| 2771 | blah |
| 2772 | blah |
| 2773 | # |
| 2774 | # Ho hum |
| 2775 | <BLANKLINE> |
| 2776 | """ |
no test coverage detected
searching dependent graphs…