• Welcome to the new COTI server. We've moved the Citizens to a new server. Please let us know in the COTI Website issue forum if you find any problems.
  • We, the systems administration staff, apologize for this unexpected outage of the boards. We have resolved the root cause of the problem and there should be no further disruptions.

ehex interface change

egor045

SOC-9
Knight
I released a Python package to manipulate eHex/pseudohex numbers a couple of weeks ago. I've simplified the package structure to make it easier to use:

- For the current unsimplified version, you import the package into your code with "from ehex.ehex import ehex"
- For the new simplified version, you import the package into your code with "from ehex import ehex"

The code is functionally identical, but if you download the new v1.0 package from PyPi you will need to change your import statements. I've tagged the old version in Github as a v0.1.1 release; the new version will be tagged as the v1.0 release.

On PyPi, both ehex-1.0.0 and ehex-0.1.1 are available; if you don't specify a version you get v1.0.0.
 
What does this mean? What kind of functions does it provide.

Code:
ehex() supports the following operations:

* Create
* Comparison
* Addition
* Subtraction

Addition/subtraction will throw a ValueError if the result is outside the range 0-33

>>> from ehex import ehex
>>> x = ehex()      # Creates ehex variable, value 0/'0'
>>> x = ehex(1)     # Creates ehex variable, value 1/'1'
>>> x = ehex('D')   # Creates ehex variable, value 13/'D'
>>> x
D
>>> int(x)
13
>>> str(x)
'D'
>>> x == 13
True
>>> x == 'D'
True
>>> x > 9
True
>>> x < 'F'
True
>>> x + 'A'
P
>>> int(x + 'A')
23
>>> x - 2
B
>>> x - '2'
B
>>> x - 35
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    x - 35
  File "ehex.py", line 146, in __sub__
    return ehex(self._value - other)
  File "ehex.py", line 31, in __init__
    raise ValueError('Invalid value {}'.format(value))
ValueError: Invalid value -22
 
While I was changing a couple raise ValueError lines in ehex 1.0.0 to work with Python 2.5, I noticed there were other raise ValueError lines in the code that were left unfinished. Values were not being put in their fields for outputting the messages of errors raised. Nothing life-threatening though.
 
Several lines that were:
Code:
raise TypeError('%s %s should be ehex, int or str', type(other), other)

I changed to:
Code:
raise TypeError('%s %s should be ehex, int or str' % (type(other), other))

So that they displayed the '%s' fields properly.
 
Several lines that were:
Code:
raise TypeError('%s %s should be ehex, int or str', type(other), other)

I changed to:
Code:
raise TypeError('%s %s should be ehex, int or str' % (type(other), other))

So that they displayed the '%s' fields properly.

Yeah, that would have been the right way to do it. Thanks - issue4 branch updated again.

If you're concerned about putting in a pull request, please don't be - I'd be very happy to have someone else contribute. Of course, pointing out what needs fixing also works ... :)
 
I can't do any of the modern Python stuff. I'm using a Classic 2.5 still. Can't even pip to PyPi because everything is HTTPS now. But I can still mention things I find.
 
Yeah, that would have been the right way to do it. Thanks - issue4 branch updated again.

If you're concerned about putting in a pull request, please don't be - I'd be very happy to have someone else contribute. Of course, pointing out what needs fixing also works ... :)

issue4 merged into master, made new release (v1.0.1). PyPi updated with 1.0.1
 
Back
Top