Source code for fml_doc_gen.write_docstring_to_file
importos
[docs]defwrite_docstring_to_file(docstring:str,output_file:str=None)->None:""" Writes the generated docstring to a specified output file. Parameters ---------- docstring : str The docstring to be written to the file. output_file : str The path to the output file. Returns ------- None This function does not return anything. Examples -------- >>> docstring = \"\"\"Parameters ---------- a : int b : int Returns ------- int \"\"\" >>> output_file = 'docstring_output.txt' >>> write_docstring_to_file(docstring, output_file) # This writes the docstring to 'docstring_output.txt' """ifoutput_file:output_dir=os.path.dirname(output_file)or"."ifnotos.path.exists(output_dir):raiseValueError(f"This directory '{output_dir}' does not exist.")ifnotos.access(output_dir,os.W_OK):raiseValueError(f"This directory '{output_dir}' is not writable")try:withopen(output_file,'w')asfile:file.write(docstring)exceptValueErrorase:print(f"An error occurred while writing to the file: {e}")