Closed ZivRonen closed 2 years ago
This is because Enlighten uses str.format() internally to do variable substitution. To escape a curly brace, you need to double it.
with enlighten.Counter(total=1, desc='A{{') as pbar:
pass
Let me know if that resolves your issue. This should probably be in the FAQ.
Yes. I just thought it can be solved in the library, or at least be documented (if it was, I missed it).
Note: In my case the values are generated dynamically (os.walk of an unknown client) so I used:
with enlighten.Counter(total=1, desc=path.replace('{', '{{').replace('}', '}}')) as pbar:
pass
which solved the issue for me.
Thanks for the quick response
P.S: If you want, I can create a pull request to solve this more generally by perform format twice. It will however slow the run a little, and will change the behavior as '{0}' will no longer be replaced in the description/unit (which I assume is unintentional, but I am not sure)
I just pushed a commit to take care of it. Let me know if it works for you. It would probably still be a good idea to add tests to protect against regression.
Checked it on my sample and it worked great! Also checked the code and it looked fine to me, I don't see a real case that someone will use the new place holder by mistake :)
Thank you!
Describe the bug Enlighten Counter try to format the description/unit fields - it will cause issues if '{' or '}' are present, in most cases raising ValueError. This happen in both progress bar and counter modes.
To Reproduce
Environment (please complete the following information):
Additional context N/A