Comments (3)
You can make a custom function which takes any number of argument and then these argument would use the format function to separate the large INT value, then append the modified args list as to print it later on using IC.
`from icecream import ic
Define a custom output function to format large integers with separators
def custom_output(*args, **kwargs):
new_args = []
for arg in args:
if isinstance(arg, int) and abs(arg) > 1000: # Check if arg is a large integer
arg = format(arg, ",") # Format large integers with commas
new_args.append(arg)
ic._print(*new_args, **kwargs)
Set the custom output function
ic.configureOutput(prefix='IC| ', outputFunction=custom_output)
Test the custom output function
ic(123456789) # This will output the formatted large integer with separators
ic("Hello", 987654321) # This will also format the large integer with separators
`
@jerabaul29 Kindly have a look at the proposed solution and close the issue. Thank you
from icecream.
Thanks for the comment. I see how this works / can work, but honestly this feels like a bit much ceremony to get this done - in this case, it is faster to use print with f-strings. I wonder if there would be a simple way to directly forward simple formatting instructions instead, that would be much lighter to use :) .
from icecream.
pprint.pformat
has the underscore_numbers keyword, which outputs numbers with _ in between, like
123_456_789
This can be used with icecream by creating a custom argToString function:
ic.configureOutput(argToStringFunction=lambda *args: pprint.pformat(*args, underscore_numbers=True))
Note that this will only work for Python >=3.10 !
from icecream.
Related Issues (20)
- icecream does not work with pytest (Failed to access the underlying source code for analysis) HOT 1
- Colorize context: highlight file name, line number and function name with different colors
- Disable/Delete line wrap HOT 1
- How to format floats in a nested dictionary?
- sdist is missing tox.ini
- 2.1.3: pytest is failing in two nits HOT 1
- How to only print what is in the parentheses? HOT 2
- Does a package exist to use icecream with logging? HOT 2
- from icecream import ic as print HOT 2
- ic does not show funtion name, *args or **kwargs inside a wrapper HOT 3
- improve string output with long strings HOT 1
- Add option to change or disable colors HOT 6
- ic| Error: Failed to access the underlying source code for analysis. HOT 6
- icecream and python HOT 1
- Getting error everytime HOT 1
- Icecream Python 3.9.12 Pyinstaller HOT 1
- How safe is this module? HOT 1
- AttributeError every time
- First call to ic() can take significant amounts of time in Pygame games, especially in debug mode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from icecream.