-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Run-time string formatting #5866
Comments
I'd like to have a function call interface to the machinery inside printf; e.g. a function that accepts the number of digits to print as an argument. Having all such things go through format strings seems silly. Just curious --- in your use case, what aspect of the formatting changes at run time? |
The use case is that the user will use a config file to specify how they format each row of a report, as rowfmt = "%10d, %10d, %10.5f ---- %10.5f %-10s" A report generation function will load the config, and apply it write the experimental results to a text file. I think something like the python |
In that case, there is only one format string determined at startup, so you could use
|
In many cases, formatting is not as simple as just to format a single number. |
The problem is that |
You can read the config file and define a global formatter function which you then call later. |
That works fine in my example:
It's obvious that formatting deals with more than single numbers. That is just an example of one primitive you'd need to have all the features of printf be run-time values. |
This works. I am not going to continue to pursue this feature. However, exposing some of the machinates underlying |
Is there a follow up issue to this? I need this and its kind of awkward we don't have a good answer for it. |
Could you describe your use case? Does my |
It does work, yes. Use-case is basically building functionality on top of |
Would this be helpful? https://github.com/tonyhffong/NumFormat.jl I wouldn't say the underlying code doesn't have smell. But at the surface it works nicely and the speed is the closest to native macro among many alternatives I have tried. |
Already have this: https://github.com/lindahua/Formatting.jl |
I several applications that I recently worked on, I find the need to do runtime string formatting -- something like:
The
@printf
macro obviously does not do the trick, as it requires the formatting string to be fixed before compile-time. I ended up writing several overly-simplified & not-so-general version of such aprintf
&sprintf
functions.I know that Musache.jl provides run-time string templates. But it seems to be too heavy-weight for simple string formatting needs and does not support C-style convenient format specification, e.g.
%f
,%d
etc.I would be great to provide such machinery in the base. Here is a tentative outline of the API design:
The text was updated successfully, but these errors were encountered: