astropy:docs
  • Index
  • Modules

Navigation

  • next »
  • « previous |
  • Astropy v5.2.1 »
  • Astropy Core Package Utilities (astropy.utils) »
  • print_code_line

print_code_line¶

astropy.utils.console.print_code_line(line, col=None, file=None, tabwidth=8, width=70)[source]¶

Prints a line of source code, highlighting a particular character position in the line. Useful for displaying the context of error messages.

If the line is more than width characters, the line is truncated accordingly and ‘…’ characters are inserted at the front and/or end.

It looks like this:

there_is_a_syntax_error_here :
                             ^
Parameters:
lineunicode

The line of code to display

colint, optional

The character in the line to highlight. col must be less than len(line).

filewritable file-like object file-like object, optional

Where to write to. Defaults to sys.stdout.

tabwidthint, optional

The number of spaces per tab ('\t') character. Default is 8. All tabs will be converted to spaces to ensure that the caret lines up with the correct column.

widthint, optional

The width of the display, beyond which the line will be truncated. Defaults to 70 (this matches the default in the standard library’s textwrap module).

Page Contents

  • print_code_line

Page Source   Back to Top

© Copyright 2011–2023, The Astropy Developers.
Created using Sphinx 6.1.2.   Last built 08 Jan 2023.