MCPcopy Index your code
hub / github.com/ipython/ipython / indent

Function indent

IPython/utils/text.py:258–290  ·  view source on GitHub ↗

Indent a string a given number of spaces or tabstops. indent(str, nspaces=4, ntabs=0) -> indent str by ntabs+nspaces. Parameters ---------- instr : basestring The string to be indented. nspaces : int (default: 4) The number of spaces to be indented. ntabs :

(instr: str, nspaces: int = 4, ntabs: int = 0, flatten: bool = False)

Source from the content-addressed store, hash-verified

256
257
258def indent(instr: str, nspaces: int = 4, ntabs: int = 0, flatten: bool = False) -> str:
259 """Indent a string a given number of spaces or tabstops.
260
261 indent(str, nspaces=4, ntabs=0) -> indent str by ntabs+nspaces.
262
263 Parameters
264 ----------
265 instr : basestring
266 The string to be indented.
267 nspaces : int (default: 4)
268 The number of spaces to be indented.
269 ntabs : int (default: 0)
270 The number of tabs to be indented.
271 flatten : bool (default: False)
272 Whether to scrub existing indentation. If True, all lines will be
273 aligned to the same indentation. If False, existing indentation will
274 be strictly increased.
275
276 Returns
277 -------
278 str : string indented by ntabs and nspaces.
279
280 """
281 ind = "\t" * ntabs + " " * nspaces
282 if flatten:
283 pat = re.compile(r'^\s*', re.MULTILINE)
284 else:
285 pat = re.compile(r'^', re.MULTILINE)
286 outstr = re.sub(pat, ind, instr)
287 if outstr.endswith(os.linesep+ind):
288 return outstr[:-len(ind)]
289 else:
290 return outstr
291
292
293def list_strings(arg: Union[str, List[str]]) -> List[str]:

Callers 6

pdocMethod · 0.90
_magic_docsMethod · 0.90
format_docstringFunction · 0.90
code_wrapMethod · 0.85
nest_caseMethod · 0.85
class_config_rst_docFunction · 0.85

Calls

no outgoing calls

Tested by 1

nest_caseMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…