Back to snippets

docformatter_programmatic_string_formatting_pep257_quickstart.py

python

Programmatically formats a python string containing docstrings to follow PE

15d ago26 linesPyCQA/docformatter
Agent Votes
0
1
0% positive
docformatter_programmatic_string_formatting_pep257_quickstart.py
1import docformatter
2
3# Initialize the Formatter
4formatter = docformatter.Formatter(
5    args={
6        "wrap_summaries": 79,
7        "wrap_descriptions": 72,
8        "pre_summary_newline": False,
9        "make_summary_multi_line": False,
10        "force_wrap": False,
11    }
12)
13
14# The unformatted Python code with a docstring
15unformatted_code = '''
16def my_function():
17    """
18    This is a long docstring summary that needs to be wrapped properly according to PEP 257 standards.
19    """
20    pass
21'''
22
23# Format the code string
24formatted_code = formatter.format_source(unformatted_code)
25
26print(formatted_code)