0

I need to use a python script to modify the docstring of a function in another python script, and save it to a file overwriting

├── test.py
├── modify.py
# test.py 'Function file of docstring to be modified'
def hello_world():
    """
    this function is a demo
    mulit lines"""
    return 'hello world'

    """
    # This is an interference note and cannot be modified here
    mulit lines"""
# modify.py 'Modify the docstring function of test.py'

from test import hello_world

def modify_docstring():

    print(hello_world.__doc__) # this function is a demo
    hello_world.__doc__ = 'I\' am new docstring' 

    print(hello_world.__doc__) # I' am new docstring  # I can assign values in this way, but only in memory. How to modify and write the test.py file?
cydia
  • 103
  • 12
  • 1
    Does this answer your question? [Insert docstring attributes in a python file](https://stackoverflow.com/questions/53564301/insert-docstring-attributes-in-a-python-file) – Gino Mempin Feb 18 '21 at 12:01
  • @GinoMempin It's a bit useful, but there are also problems. The triple quotes in the docstring that comes after parsing become single quotes, while the multi-line docstrings are directly connected into one line with the \n symbol. This is fatal. I don't know if there is any way to deal with it. – cydia Feb 19 '21 at 10:22

0 Answers0