Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé
Module « doctest » Python 3.13.2

Fonction script_from_examples - module doctest

Signature de la fonction script_from_examples

def script_from_examples(s) 

Description

help(doctest.script_from_examples)

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.
...
...           Python has super accurate integer addition
...
...           >>> 2 + 2
...           5
...
...           And very friendly error messages:
...
...           >>> 1/0
...           To Infinity
...           And
...           Beyond
...
...           You can use logic if you want:
...
...           >>> if 0:
...           ...    blah
...           ...    blah
...           ...
...
...           Ho hum
...           '''

>>> print(script_from_examples(text))
# Here are examples of simple math.
#
#     Python has super accurate integer addition
#
2 + 2
# Expected:
## 5
#
#     And very friendly error messages:
#
1/0
# Expected:
## To Infinity
## And
## Beyond
#
#     You can use logic if you want:
#
if 0:
   blah
   blah
#
#     Ho hum
<BLANKLINE>


Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé