Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format.jl formatters #253

Closed
jariji opened this issue Nov 26, 2024 · 1 comment
Closed

Format.jl formatters #253

jariji opened this issue Nov 26, 2024 · 1 comment

Comments

@jariji
Copy link
Contributor

jariji commented Nov 26, 2024

I would like to use formatters with the Format.jl syntax because I prefer that Python format syntax to printf syntax. Could that be supported internally or with an extension?

@ronisbr
Copy link
Owner

ronisbr commented Nov 26, 2024

Hi @jariji !

Since a formatter is any function that returns an object to be rendered, you can do the following:

julia> using PrettyTables, Format

julia> A = rand(5, 5);

julia> pretty_table(A; formatters = (v, i, j) -> pyfmt("<8.4f", v))
┌──────────┬──────────┬──────────┬──────────┬──────────┐
│   Col. 1 │   Col. 2 │   Col. 3 │   Col. 4 │   Col. 5 │
├──────────┼──────────┼──────────┼──────────┼──────────┤
│ 0.24290.54660.28930.72740.1475   │
│ 0.43030.14520.68560.73560.5197   │
│ 0.67040.20770.79660.98450.5619   │
│ 0.11070.91950.40490.15840.0652   │
│ 0.69110.90130.34160.94530.9984   │
└──────────┴──────────┴──────────┴──────────┴──────────┘

@ronisbr ronisbr closed this as completed Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants