obspy.core.util.misc.wrap_long_string¶
- wrap_long_string(string, line_length=79, prefix=u'', special_first_prefix=None, assumed_tab_width=8, sloppy=False)[source]¶
Reformat a long string, wrapping it to a specified length.
Parameters: - string (str) Input string to wrap
- line_length (int) total target length of each line, including the prefix if specified
- prefix (str, optional) common prefix used to start the line (e.g. some spaces, tabs for indentation)
- special_first_prefix (str, optional) special prefix to use on the first line, instead of the general prefix
- assumed_tab_width (int) if the prefix strings include tabs the line length can not be computed exactly. assume a tab in general is equivalent to this many spaces.
- sloppy (bool) Controls the behavior when a single word without spaces is to long to fit on a single line. Default (False) is to allow a single line to be longer than the specified line length. If set to True, Long words will be force-hyphenated to fit the line.
Deprecated since version 0.10.0: The wrap_long_string function is deprecated. Please use the textwrap module from the standard library instead.
Examples
>>> string = ("Retrieve an event based on the unique origin " ... "ID numbers assigned by the IRIS DMC") >>> print(wrap_long_string(string, prefix=" * > ", ... line_length=50)) * > Retrieve an event based on * > the unique origin ID numbers * > assigned by the IRIS DMC >>> print(wrap_long_string(string, prefix=" * ", ... line_length=70)) * Retrieve an event based on the unique origin ID * numbers assigned by the IRIS DMC >>> print(wrap_long_string(string, prefix=" > ", ... special_first_prefix=" * ", ... line_length=50)) * Retrieve an event based on > the unique origin ID numbers > assigned by the IRIS DMC >>> problem_string = ("Retrieve_an_event_based_on_the_unique " ... "origin ID numbers assigned by the IRIS DMC") >>> print(wrap_long_string(problem_string, prefix=" ", ... line_length=40, sloppy=True)) Retrieve_an_event_based_on_the_unique origin ID numbers assigned by the IRIS DMC >>> print(wrap_long_string(problem_string, prefix=" ", ... line_length=40)) Retrieve_an_event_base d_on_the_unique origin ID numbers assigned by the IRIS DMC