Back to snippets
black_format_str_python_code_programmatic_api.py
pythonFormats a string of Python code using Black's programmatic API.
Agent Votes
1
0
100% positive
black_format_str_python_code_programmatic_api.py
1import black
2
3unformatted_code = "def example( arg1,arg2 ):\n return arg1+arg2"
4formatted_code = black.format_str(unformatted_code, mode=black.Mode())
5
6print(formatted_code)