Dear NumPy Community,

I would like to propose an enhancement to NumPy's print options that allows
them to be initialized from environment variables. This would provide a
more convenient way to configure array formatting without modifying source
code.
Background

Currently, NumPy print options are initialized with default values and can
be modified using numpy.set_printoptions() or the numpy.printoptions
context manager. While effective, these approaches require explicit
modifications to the source code, which is not always convenient. This
discussion has been started on GitHub in issue #22188
<https://github.com/numpy/numpy/issues/22188>.
Proposal

I propose that NumPy print options be initialized from environment
variables prefixed with NUMPY_PRINTOPTION_. For example, the precision
option could be set using

export NUMPY_PRINTOPTION_PRECISION=4

or on-demand execution as follows.

NUMPY_PRINTOPTION_LINEWIDTH=120 python my-fancy-solver.py

This approach has several advantages.

   1.

   *Better Utilization of Wide Displays* The default line width of 80 is
   reasonable, but modern screens and terminals allow for wider output.
   Environment variables would provide a simple way to adjust this setting
   without modifying the code.
   2.

   *No Source Code Modification Required* Changing print options via
   np.printoptions requires access to a text editor, which may not always
   be available (e.g., in isolated environments like Docker containers). Using
   environment variables allows for quick, non-invasive configuration.
   3.

   *Familiar and Well-Understood Mechanism* Environment variables are a
   widely used and standard approach for configuring software behavior, making
   them a natural fit for setting print options.

I would appreciate feedback on this idea, particularly regarding
implementation details and any potential issues that might arise. Looking
forward to hearing your thoughts.

Best regards,
Daniel Bershatsky
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to