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)
| 247 | |
| 248 | |
| 249 | def 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 | |
| 288 | def list_strings(arg): |
no outgoing calls