Output

Text display and export utilities.

Output utilities for exporting and displaying results.

Provides:
  • Text output for terminal/console

  • CSV export for data files

  • PDF export for reports (requires reportlab)

Example

>>> from mechlab.output import print_stress, export_csv
>>> print_stress(state)
>>> export_csv(results, 'results.csv')
mechlab.output.print_stress(state, precision=2)[source]

Print stress analysis results in formatted text.

Parameters:
  • state (StressState) – StressState object with stress values

  • precision (int) – Number of decimal places

Return type:

None

Example

>>> from mechlab.mechanics.stress import StressState
>>> state = StressState(100, 50, 25)
>>> print_stress(state)
mechlab.output.print_beam(beam, precision=4)[source]

Print beam analysis results in formatted text.

Parameters:
  • beam (SimplySupportedBeam) – SimplySupportedBeam object

  • precision (int) – Number of significant figures

Return type:

None

mechlab.output.print_results(results, title='Results', precision=6)[source]

Print a results dictionary in formatted table.

Parameters:
  • results (dict[str, Any]) – Dictionary of result key-value pairs

  • title (str) – Title to display above results

  • precision (int) – Number of significant figures for floats

Return type:

None

mechlab.output.export_csv(results, filename, include_header=True)[source]

Export analysis results to CSV file.

Parameters:
  • results (dict[str, Any]) – Dictionary of result key-value pairs

  • filename (str | Path) – Output CSV filename or path

  • include_header (bool) – Whether to include column headers

Return type:

None

Example

>>> results = {'σ1': 112.5, 'σ2': 37.5, 'unit': 'MPa'}
>>> export_csv(results, 'stress_results.csv')
mechlab.output.export_csv_table(data, filename, fieldnames=None)[source]

Export list of dictionaries to CSV table.

Parameters:
  • data (list[dict[str, Any]]) – List of dictionaries with consistent keys

  • filename (str | Path) – Output CSV filename or path

  • fieldnames (list[str] | None) – Column names (defaults to keys from first row)

Return type:

None

Text Display

mechlab.output.print_stress(state, precision=2)[source]

Print stress analysis results in formatted text.

Parameters:
  • state (StressState) – StressState object with stress values

  • precision (int) – Number of decimal places

Return type:

None

Example

>>> from mechlab.mechanics.stress import StressState
>>> state = StressState(100, 50, 25)
>>> print_stress(state)
mechlab.output.print_beam(beam, precision=4)[source]

Print beam analysis results in formatted text.

Parameters:
  • beam (SimplySupportedBeam) – SimplySupportedBeam object

  • precision (int) – Number of significant figures

Return type:

None

mechlab.output.print_results(results, title='Results', precision=6)[source]

Print a results dictionary in formatted table.

Parameters:
  • results (dict[str, Any]) – Dictionary of result key-value pairs

  • title (str) – Title to display above results

  • precision (int) – Number of significant figures for floats

Return type:

None

Export

mechlab.output.export_csv(results, filename, include_header=True)[source]

Export analysis results to CSV file.

Parameters:
  • results (dict[str, Any]) – Dictionary of result key-value pairs

  • filename (str | Path) – Output CSV filename or path

  • include_header (bool) – Whether to include column headers

Return type:

None

Example

>>> results = {'σ1': 112.5, 'σ2': 37.5, 'unit': 'MPa'}
>>> export_csv(results, 'stress_results.csv')
mechlab.output.export_csv_table(data, filename, fieldnames=None)[source]

Export list of dictionaries to CSV table.

Parameters:
  • data (list[dict[str, Any]]) – List of dictionaries with consistent keys

  • filename (str | Path) – Output CSV filename or path

  • fieldnames (list[str] | None) – Column names (defaults to keys from first row)

Return type:

None

PDF Export

Note

PDF export requires the reportlab package:

pip install reportlab
mechlab.output.export_pdf(results, filename, title='MechLab Analysis Report')

Export analysis results to PDF file.

Parameters:
  • results – Dictionary of result key-value pairs

  • filename – Output PDF filename or path

  • title – Report title (default: “MechLab Analysis Report”)