Skip to main content

docstringFormatter

Format docstring to be able to entry in DeepL or GoogleTranslate.

Main function:
    1. Remove newline
    2. Reduce extra spaces
    3. Output result as txt-file

"docstringFormatter" releases you from boring duties to reform the docstring string in the Entry of DeepL or GoogleTranslate so that these get correct translation.

DEMO

Below show the console display when get docstring of logging.Logger object.

____ "logging" is one of the standard libraries of Python.

Compared with "Original Sentence" section, the strings of "Formatted Sentence" is converted in one line by removing newlines and extra spaces that consist of indention of left side.

Only the left thing you do is copy & paste the strings of "Formatted Sentence" in the Entry of Translating Web Application like DeepL or GoogleTranslate.

■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
   Formatted Sentence   
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Instances of the Logger class represent a single logging channel. A "logging channel" indicates an area of an application. Exactly how an "area" is defined is up to the application developer. Since an application can have any number of areas, logging channels are identified by a unique string. Application areas can be nested (e.g. an area of "input processing" might include sub-areas "read CSV files", "read XLS files" and "read Gnumeric files"). To cater for this natural nesting, channel names are organized into a namespace hierarchy where levels are separated by periods, much like the Java or Python package namespace. So in the instance given above, channel names might be "input" for the upper level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels. There is no arbitrary limit to the depth of nesting. 

■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
   Original Sentence   
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

    Instances of the Logger class represent a single logging channel. A
    "logging channel" indicates an area of an application. Exactly how an
    "area" is defined is up to the application developer. Since an
    application can have any number of areas, logging channels are identified
    by a unique string. Application areas can be nested (e.g. an area
    of "input processing" might include sub-areas "read CSV files", "read
    XLS files" and "read Gnumeric files"). To cater for this natural nesting,
    channel names are organized into a namespace hierarchy where levels are
    separated by periods, much like the Java or Python package namespace. So
    in the instance given above, channel names might be "input" for the upper
    level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels.
    There is no arbitrary limit to the depth of nesting.
    

Features

  1. Easy to Use
    __ You can use the function just adjust content of main() in code.
  2. Easy to Read
    __ Console display is designated simply and reasonably.
  3. Easy to Introduce
    __ Mainly 2ways to use are described in this README.

Requirement

"docstringFormatter" (ver.1.0.0) doesn't require third-party Library. Probably, it works on over Python3.7.x Envelopment.

  • Python 3.7.x

Installation

Install "docstringFormatter" with pip command.

pip install docstringFormatter

Usage

There are 2 way for usage. One hand is (1) script running alone. Another is (2) import functions (or whole module).

(1) Run the "docstringFormatter.py" and use the main() in itself

Open the python file named "docstringFormatter.py" with any text editor and so on.

Then change the assignment for var name_object in main() to the identifier of the object you want to get docstring.

If you want the result as a txt-file, revalue the arguments of txt_outputter() appropriately.

See the comments in the below code for details.

def main():
    """
    You can try the function here.
    """

    # If the object requires import of module, you do so like the under example 'logging'
    import logging
    # Assign the identifier of object to 'name_object'
    name_object = logging.Logger
    # Default Setting at main() --> name_obj=name_object, times_red=2, rmv_t=True, rmv_n=True
    str_result = docstring_formatter(name_obj=name_object, times_red=2, rmv_t=True, rmv_n=True)

    console_constructor(str_result, name_object.__doc__)

    # If you need the output txt-file, revalue the 'output' arg to True.
    # You can change the output file name by rewriting 'filename' arg.
    txt_outputter(output=False, filename='docstring_formatted')

    # When you want the output is the same as 'Original Sentence' displayed on console,
    # revalue the arguments setting of docstring_formatter() like below.
    #
    # Setting at main() --> name_obj=name_object, times_red=0, rmv_t=False, rmv_n=False

(2) Importing three functions by copy&paste contents of main()

Introducing to your code is also simple.

First import at top in your cord.The example is shown below.

And Just copy & paste the contents of main() to the appropriate line.
Remember to delete the left side indent of pasted code.

# import sentences example in case you'll copy & paste contents of main()
from src.docstringFormatter import docstring_formatter
from src.docstringFormatter import console_constructor
from src.docstringFormatter import txt_outputter

Import as a module not multi functions

Sure, you can import this script as a module. If you can code, try it yourself!

Note

I don't test the Environments under Linux and Mac.

Author

License

"docstringFormatter" is under MIT license.

Release files for docstringFormatter 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docstringFormatter 1.0.0
File Size Uploaded
docstringFormatter-1.0.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docstringFormatter 1.0.0
File Interpreter ABI Platform
docstringFormatter-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / docstringFormatter-1.0.0.tar.gz

Download URL docstringFormatter-1.0.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cbdef559826c3f65c34d6e033e6fbf033b82a9716733ef7abfd90ca1fa1eedf5
BLAKE2b-256 checksum
How to use checksums
ec7867becf81a99fd4a00453311debf3169dba03079f957a3ad648d800cea8ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / docstringFormatter-1.0.0-py3-none-any.whl

Download URL docstringFormatter-1.0.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eaaf24b8587a9ea127442c0fc34f034775068daef77f87558ad83d1aaf15b54d
BLAKE2b-256 checksum
How to use checksums
8f9ccdb9e48a194e083300bd011b429f2a2d514482e7372e329d35ab88a479dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page