Miscellaneous stuff that doesn’t really fit anywhere else.


Print *args if SYMPY_DEBUG is True, else do nothing.


If SYMPY_DEBUG is True, it will print a nice execution tree with arguments and results of all decorated functions, else do nothing.

sympy.utilities.misc.filldedent(s, w=70)[source]

Strips leading and trailing empty lines from a copy of \(s\), then dedents, fills and returns it.

Empty line stripping serves to deal with docstrings like this one that start with a newline after the initial triple quote, inserting an empty line at the beginning of the string.

sympy.utilities.misc.find_executable(executable, path=None)[source]

Try to find ‘executable’ in the directories listed in ‘path’ (a string listing directories separated by ‘os.pathsep’; defaults to os.environ[‘PATH’]). Returns the complete filename or None if not found


Return function name of \(x\) (if defined) else the \(type(x)\). See Also ======== sympy.core.compatibility get_function_name


Return a cut-and-pastable string that, when printed, is equivalent to the input. The string returned is formatted so it can be indented nicely within tests; in some cases it is wrapped in the dedent function which has to be imported from textwrap.


Note: because there are characters in the examples below that need to be escaped because they are themselves within a triple quoted docstring, expressions below look more complicated than they would be if they were printed in an interpreter window.

>>> from sympy.utilities.misc import rawlines
>>> from sympy import TableForm
>>> s = str(TableForm([[1, 10]], headings=(None, ['a', 'bee'])))
>>> print(rawlines(s)) # the \ appears as \ when printed
    'a bee\n'
    '1 10 '
>>> print(rawlines('''this
... that'''))
>>> print(rawlines('''this
... that
... '''))
>>> s = """this
... is a triple '''
... """
>>> print(rawlines(s))
    is a triple '''
>>> print(rawlines('''this
... that
...     '''))
    '    '
sympy.utilities.misc.replace(string, *reps)[source]

Return string with all keys in reps replaced with their corresponding values, longer strings first, irrespective of the order they are given. reps may be passed as tuples or a single mapping.




>>> from sympy.utilities.misc import replace
>>> replace('foo', {'oo': 'ar', 'f': 'b'})
>>> replace("spamham sha", ("spam", "eggs"), ("sha","md5"))
'eggsham md5'

There is no guarantee that a unique answer will be obtained if keys in a mapping overlap (i.e. are the same length and have some identical sequence at the beginning/end):

>>> reps = [
...     ('ab', 'x'),
...     ('bc', 'y')]
>>> replace('abc', *reps) in ('xc', 'ay')
sympy.utilities.misc.translate(s, a, b=None, c=None)[source]

Return s where characters have been replaced or deleted.


>>> from sympy.utilities.misc import translate
>>> from sympy.core.compatibility import unichr
>>> abc = 'abc'
>>> translate(abc, None, 'a')
>>> translate(abc, {'a': 'x'}, 'c')
>>> translate(abc, {'abc': 'x', 'a': 'y'})
>>> translate('abcd', 'ac', 'AC', 'd')

There is no guarantee that a unique answer will be obtained if keys in a mapping overlap are the same length and have some identical sequences at the beginning/end:

>>> translate(abc, {'ab': 'x', 'bc': 'y'}) in ('xc', 'ay')


translate(s, None, deletechars):
all characters in deletechars are deleted
translate(s, map [,deletechars]):
all characters in deletechars (if provided) are deleted then the replacements defined by map are made; if the keys of map are strings then the longer ones are handled first. Multicharacter deletions should have a value of ‘’.
translate(s, oldchars, newchars, deletechars)
all characters in deletechars are deleted then each character in oldchars is replaced with the corresponding character in newchars

Previous topic


Next topic


This Page