Giter Club home page Giter Club logo

Comments (3)

Muhammad-Musab avatar Muhammad-Musab commented on June 14, 2024

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.

jerabaul29 avatar jerabaul29 commented on June 14, 2024

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.

salabim avatar salabim commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.