Closed sledgeh4w closed 1 year ago
Do you mean in the elf header object, there are attributes that are int
, and you want to print them as hex? That sounds like an interesting feature. I guess I can implement a way to customize print for a certain type.
Yes, the way you said would be more general.
I have a proposal for addressing this issue. I am considering adding two more arguments to the config: int_to_hex(False)
and int_to_bin(False)
to enable printing all int
type objects as either hexadecimal or binary. We could potentially include an option for octal representation as well.
If both arguments are set to True
, the op()
call could either return an error indicating a conflicting configuration or prioritize the desired format (preferably hexadecimal).
I believe this solution would provide a more general and customizable approach to handling different number representations. If you agree that this would be a good fix for the problem, I would be happy to implement it.
Sorry I forgot to reply to this proposal. I don’t think having a hook for the integer is a generic solution for this issue. Python already have many formatting capabilities and we should not reinvent the wheels. I believe we should add a register method for the op object so the users can register a representative function (similar to str) and return an arbitrary string they like. We can’t format every possibility, we should leave the flexibility to the user and provide them a way to hook in their formatting functions.
Sure, this sounds like a better solution. To what extent should this representative function cover? For example, should we only give users the ability to customize basic data types like int
, float
, str
, etc. or should we also support custom representation for more complicated structures like dict
, list
, etc?
BTW, I am closing the pull request.
The register function should take a type and a function that returns a string. It would cover all the use cases, including customized classes.
Solved in #91
I use
objpring
to print the elf header object, hope the number can be displayed in hexadecimal.