Giter Site home page Giter Site logo

Comments (2)

xiaoxstz avatar xiaoxstz commented on June 15, 2024

I found several usages:

For example, bit_length

python calc.py 1                  # output: 2
python calc.py 1 bit_length # output: 2

python calc.py 12                   # output: 24
python calc.py 12 bit_length # output: 5

python calc.py 123                  # output: 246
python calc.py 123 bit_length # output: 8

python calc.py 1234                  # output: 2468
python calc.py 1234 bit_length # output: 12

But, I don't how bit_length works. The result seems not true.

Similarly, we can use other commands

# is_integer: it seems useful
python calc.py 12.2                   # output: 24.4
python calc.py 12.2 is_integer  # output: False

python calc.py 12.5                   # output: 25.0
python calc.py 12.5 is_integer  # output: True

# as_integer_ratio: I don't understand
python calc.py 12.2 as_integer_ratio  # output: [3433994715870003, 140737488355328]
python calc.py 12.5 as_integer_ratio  # output: [25, 1]

# bit_count: I don't understand
python calc.py 12.2 bit_count              # throw error
python calc.py 12.2 bit_count   2         # throw error
python calc.py 12.2 bit_count   "sdf"   # throw error
python calc.py 12.2 bit_count --help   # works. It shows the help about some commands:  as_integer_ratio, conjugate,hex, is_integer

Then, I use python calc.py 12.2 bit_count --help to check help information

NAME
    calc.py 12.2

SYNOPSIS
    calc.py 12.2 COMMAND | VALUE

COMMANDS
    COMMAND is one of the following:

     as_integer_ratio
       Return a pair of integers, whose ratio is exactly equal to the original float.

     conjugate
       Return self, the complex conjugate of any float.

     fromhex
       Create a floating-point number from a hexadecimal string.

     hex
       Return a hexadecimal representation of a floating-point number.

     is_integer
       Return True if the float is an integer.

VALUES
    VALUE is one of the following:

     imag

     real

OK, It told me I can use as_integer_ratio, conjugate,hex, and is_integer

However, there seems be some issues.

python calc.py 12.2 hex  # output: 0x1.8666666666666p+4
python calc.py 12.5 hex  # output: 0x1.9000000000000p+4
python calc.py 5 hex       # throw error! why?

from python-fire.

xiaoxstz avatar xiaoxstz commented on June 15, 2024

Outputs with different data types have different available commands.

For example, you can see different commands help with the commands below.

python calc.py 1 --help     
python calc.py 1.1 --help   
python calc.py "abc" --help 
python calc.py abc --help   

from python-fire.

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.