Skip to main content
Ctrl+K
Astropy v7.0.1 - Home Astropy v7.0.1 - Home
  • Getting Started
  • User Guide
  • Contributing
  • Project Details
  • Tutorials
  • GitHub
  • Getting Started
  • User Guide
  • Contributing
  • Project Details
  • Tutorials
  • GitHub

Section Navigation

Data structures and transformations

  • Constants (astropy.constants)
  • Units and Quantities (astropy.units)
  • N-Dimensional Datasets (astropy.nddata)
  • Data Tables (astropy.table)
  • Time and Dates (astropy.time)
  • Time Series (astropy.timeseries)
  • Astronomical Coordinate Systems (astropy.coordinates)
  • World Coordinate System (astropy.wcs)
  • Models and Fitting (astropy.modeling)
  • Uncertainties and Distributions (astropy.uncertainty)

Files, I/O, and Communication

  • Unified File Read/Write Interface
  • FITS File Handling (astropy.io.fits)
  • ASCII Tables (astropy.io.ascii)
  • VOTable XML Handling (astropy.io.votable)
  • Miscellaneous: HDF5, YAML, Parquet, pickle (astropy.io.misc)
  • Astropy I/O Typing (astropy.io.typing)
  • SAMP (Simple Application Messaging Protocol) (astropy.samp)

Computations and utilities

  • Cosmological Calculations (astropy.cosmology)
  • Convolution and Filtering (astropy.convolution)
  • IERS data access (astropy.utils.iers)
  • Data Visualization (astropy.visualization)
  • Astrostatistics Tools (astropy.stats)

Nuts and bolts

  • Configuration System (astropy.config)
  • I/O Registry (astropy.io.registry)
  • Logging system
  • Python warnings system
  • Astropy Core Package Utilities (astropy.utils)
    • IERS data access (astropy.utils.iers)
    • Downloadable Data Management (astropy.utils.data)
    • Masked Values (astropy.utils.masked)
    • Reference/API
  • Astropy Glossary
  • User Guide
  • Astropy Core Package Utilities (astropy.utils)
  • Reference/API
  • 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

colpython:int, optional

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

filefile-like (writeable), optional

Where to write to. Defaults to sys.stdout.

tabwidthpython:int, 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.

widthpython:int, 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).

previous

human_file_size

next

terminal_size

Edit

© Copyright 2011–2025, The Astropy Developers.

Created using Sphinx 8.1.3.

Built with the PyData Sphinx Theme 0.16.1.