-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Practical Generative AI with ChatGPT
By :

Whenever you’re working with new applications or projects, it is always good practice to correlate your code with documentation. It might be in the form of a docstring that you can embed in your functions or classes so that others can invoke them directly in the development environment.
For example, let’s consider the same function developed in the previous section and make it a Python class:
class UnderscoreAdder:
def __init__(self, word):
self.word = word
def add_underscores(self):
return "_".join(self.word) # More efficient
We can test it as follows:
Figure 5.12: Testing the UnderscoreAdder class
Now, let’s say I want to be able to retrieve the docstring documentation using the UnderscoreAdder?
convention. By doing so with Python packages, functions, and methods, we have full documentation of the capabilities of that specific object, as follows (an example with the...