MCPcopy Create free account
hub / github.com/ipython/ipython / indent

Function indent

IPython/utils/text.py:249–285  ·  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 : i

(instr,nspaces=4, ntabs=0, flatten=False)

Source from the content-addressed store, hash-verified

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

Callers 6

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

Calls

no outgoing calls

Tested by 1

nest_caseMethod · 0.68