How to use 'python __str__' in Python

Every line of 'python __str__' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
93def py_str(py):
94 '''Turns a python value into a string of python code
95 representing that object'''
96 def maybe_str(s):
97 return s if isinstance(s, str) and '(' in s else repr(s)
98
99 if type(py) is dict:
100 return '{' + ', '.join(
101 [repr(k) + ': ' + maybe_str(py[k]) for k in py]) + '}'
102 if not isinstance(py, basestring):
103 return repr(py)
104 else:
105 return py
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets