Skip to main content
Ctrl+K
Astropy
  • About
    • About Astropy
    • Code of Conduct
    • Acknowledging & Citing
    • History
  • Documentation
    • astropy
    • asdf-astropy
    • astropy-healpix
    • astroquery
    • ccdproc
    • photutils
    • regions
    • reproject
    • specreduce
    • specutils
  • Get Help
  • Contribute
  • Affiliated Packages
  • Team
  • GitHub
  • About ▾
    • About Astropy
    • Code of Conduct
    • Acknowledging & Citing
    • History
  • Documentation ▾
    • astropy
    • asdf-astropy
    • astropy-healpix
    • astroquery
    • ccdproc
    • photutils
    • regions
    • reproject
    • specreduce
    • specutils
  • Get Help
  • Contribute
  • Affiliated Packages
  • Team
  • GitHub
Logo image

Astropy v8.0.0b1

  • Getting Started
  • User Guide
    • 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)
    • Overview of Astropy File I/O
    • High-level Unified File I/O
    • FITS File Handling (astropy.io.fits)
    • Text Tables (astropy.io.ascii)
    • VOTable Handling (astropy.io.votable)
    • ECVS, HDF5, Parquet, PyArrow CSV, YAML (astropy.io.misc)
    • Cosmological Calculations (astropy.cosmology)
    • Convolution and Filtering (astropy.convolution)
    • IERS data access (astropy.utils.iers)
    • Data Visualization (astropy.visualization)
    • Astrostatistics Tools (astropy.stats)
    • Masked Values and Quantities (astropy.utils.masked)
    • SAMP (Simple Application Messaging Protocol) (astropy.samp)
    • Configuration System (astropy.config)
    • I/O Registry (astropy.io.registry)
    • I/O Typing (astropy.io.typing)
    • Logging system
    • Python warnings system
    • Astropy Core Package Utilities (astropy.utils)
      • Downloadable Data Management (astropy.utils.data)
      • Reference/API
        • make_function_with_signature
        • HomogeneousList
        • color_print
        • human_file_size
        • human_time
        • isatty
        • print_code_line
        • terminal_size
        • ProgressBar
        • ProgressBarOrSpinner
        • Spinner
        • data_info_factory
        • dtype_info_name
        • BaseColumnInfo
        • DataInfo
        • MixinInfo
        • ParentDtypeInfo
        • deprecated
        • deprecated_attribute
        • deprecated_renamed_argument
        • format_doc
        • classproperty
        • lazyproperty
        • sharedmethod
        • diff_values
        • report_diff_values
        • where_not_allclose
        • AstropyBackwardsIncompatibleChangeWarning
        • AstropyDeprecationWarning
        • AstropyPendingDeprecationWarning
        • AstropyUserWarning
        • AstropyWarning
        • DuplicateRepresentationWarning
        • Conf
        • IERS
        • IERSDegradedAccuracyWarning
        • IERSRangeError
        • IERSStaleWarning
        • IERSWarning
        • IERS_A
        • IERS_Auto
        • IERS_B
        • LeapSeconds
        • earth_orientation_table
        • find_current_module
        • isinstancemethod
        • minversion
        • resolve_name
        • enable_merge_strategies
        • merge
        • common_dtype
        • MetaAttribute
        • MetaData
        • MergeNpConcatenate
        • MergePlus
        • MergeStrategy
        • MergeConflictError
        • MergeConflictWarning
        • dtype_bytes_or_chars
        • find_api_page
        • format_exception
        • indent
        • isiterable
        • online_help
        • silence
        • JsonCustomEncoder
        • NumpyRNGContext
        • lex
        • yacc
        • ThreadSafeParser
        • ScienceState
        • check_broadcast
        • simplify_basic_index
        • unbroadcast
        • IncompatibleShapeError
        • NDArrayShapeMethods
        • ShapedLikeNDArray
        • system_info
        • cache_contents
        • cache_total_size
        • check_download_cache
        • check_free_space_in_dir
        • clear_download_cache
        • compute_hash
        • download_file
        • download_files_in_parallel
        • export_download_cache
        • get_cached_urls
        • get_file_contents
        • get_free_space_in_dir
        • get_pkg_data_contents
        • get_pkg_data_filename
        • get_pkg_data_filenames
        • get_pkg_data_fileobj
        • get_pkg_data_fileobjs
        • get_pkg_data_path
        • get_readable_fileobj
        • import_download_cache
        • import_file_to_cache
        • is_url
        • is_url_in_cache
        • CacheDamaged
        • CacheMissingWarning
        • Conf
        • check_anyuri
        • check_id
        • check_mime_content_type
        • check_token
        • fix_id
        • get_xml_encoding
        • get_xml_iterator
        • xml_readlines
        • unescape_all
        • validate_schema
        • XMLWriter
    • Environment variables
    • Astropy Glossary
  • Contributing
  • Project Details
  • 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

isatty

next

terminal_size

Edit

© Copyright 2011–2026, The Astropy Developers.

Code of Conduct

Updated on 21 May 2026 , built with Sphinx 9.1.0