istr-python 1.1.29__tar.gz → 1.1.30__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {istr_python-1.1.29 → istr_python-1.1.30}/PKG-INFO +41 -1
- {istr_python-1.1.29 → istr_python-1.1.30}/README.md +40 -0
- {istr_python-1.1.29 → istr_python-1.1.30}/istr/istr.py +27 -1
- {istr_python-1.1.29 → istr_python-1.1.30}/istr_python.egg-info/PKG-INFO +41 -1
- {istr_python-1.1.29 → istr_python-1.1.30}/pyproject.toml +1 -1
- {istr_python-1.1.29 → istr_python-1.1.30}/tests/test_istr.py +18 -1
- {istr_python-1.1.29 → istr_python-1.1.30}/istr/LICENSE.txt +0 -0
- {istr_python-1.1.29 → istr_python-1.1.30}/istr/__init__.py +0 -0
- {istr_python-1.1.29 → istr_python-1.1.30}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.1.29 → istr_python-1.1.30}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.1.29 → istr_python-1.1.30}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.1.29 → istr_python-1.1.30}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.30
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -548,6 +548,46 @@ istr('0456')[::-1] ==> istr('6540')
|
|
|
548
548
|
> istr(-456).reversed() + 3 ==> TypeError
|
|
549
549
|
> ```
|
|
550
550
|
|
|
551
|
+
|
|
552
|
+
#### ceil
|
|
553
|
+
|
|
554
|
+
The `istr.ceil` method can be used to find the smallest integer, divisible by a given number (divisible_by), greater than or equal to the value.
|
|
555
|
+
This can be useful to step through all multiples of n, >= m, like:
|
|
556
|
+
|
|
557
|
+
```
|
|
558
|
+
for i in istr.range(istr(1000/3, 10000, 3)) ==> # 1002, 1005, ... 9999
|
|
559
|
+
for i in istr.count(int(istr,ceil(1000/3)), 3)) ==> 1002, 1005, ...
|
|
560
|
+
```
|
|
561
|
+
Examples:
|
|
562
|
+
```
|
|
563
|
+
istr(1000).ceil() ==> 1000 # divisible_by is 1 by default
|
|
564
|
+
istr(1000).ceil(2) ==> 1000
|
|
565
|
+
istr(1000).ceil(3) ==> 1002
|
|
566
|
+
```
|
|
567
|
+
It is also possible to use the ceil method for floats or ints:
|
|
568
|
+
```
|
|
569
|
+
istr.ceil(1000.2) ==> 1001
|
|
570
|
+
istr.ceil(1000.2, 2) ==> 1002
|
|
571
|
+
istr.ceil(1000.2, 3 ==> 1002
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
#### floor
|
|
575
|
+
|
|
576
|
+
The `istr.floor` method can be used to find the largest integer, divisible by a given number (divisible_by), smaller than or equal to the value.
|
|
577
|
+
|
|
578
|
+
Examples:
|
|
579
|
+
```
|
|
580
|
+
istr(1000).floor() ==> 1000 # divisible_by is 1 by default
|
|
581
|
+
istr(1000).floor(2) ==> 1000
|
|
582
|
+
istr(1000).floor(3) ==> 999
|
|
583
|
+
```
|
|
584
|
+
It is also possible to use the ceil method for floats or ints:
|
|
585
|
+
```
|
|
586
|
+
istr.floor(1000.2) ==> 1000
|
|
587
|
+
istr.floor(1000.2, 2) ==> 1000
|
|
588
|
+
istr.floor(1000.2, 3 ==> 999
|
|
589
|
+
```
|
|
590
|
+
|
|
551
591
|
#### enumerate with istrs
|
|
552
592
|
|
|
553
593
|
The `istr.enumerate` class method can be used just as the built-in enumerate function.
|
|
@@ -535,6 +535,46 @@ istr('0456')[::-1] ==> istr('6540')
|
|
|
535
535
|
> istr(-456).reversed() + 3 ==> TypeError
|
|
536
536
|
> ```
|
|
537
537
|
|
|
538
|
+
|
|
539
|
+
#### ceil
|
|
540
|
+
|
|
541
|
+
The `istr.ceil` method can be used to find the smallest integer, divisible by a given number (divisible_by), greater than or equal to the value.
|
|
542
|
+
This can be useful to step through all multiples of n, >= m, like:
|
|
543
|
+
|
|
544
|
+
```
|
|
545
|
+
for i in istr.range(istr(1000/3, 10000, 3)) ==> # 1002, 1005, ... 9999
|
|
546
|
+
for i in istr.count(int(istr,ceil(1000/3)), 3)) ==> 1002, 1005, ...
|
|
547
|
+
```
|
|
548
|
+
Examples:
|
|
549
|
+
```
|
|
550
|
+
istr(1000).ceil() ==> 1000 # divisible_by is 1 by default
|
|
551
|
+
istr(1000).ceil(2) ==> 1000
|
|
552
|
+
istr(1000).ceil(3) ==> 1002
|
|
553
|
+
```
|
|
554
|
+
It is also possible to use the ceil method for floats or ints:
|
|
555
|
+
```
|
|
556
|
+
istr.ceil(1000.2) ==> 1001
|
|
557
|
+
istr.ceil(1000.2, 2) ==> 1002
|
|
558
|
+
istr.ceil(1000.2, 3 ==> 1002
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
#### floor
|
|
562
|
+
|
|
563
|
+
The `istr.floor` method can be used to find the largest integer, divisible by a given number (divisible_by), smaller than or equal to the value.
|
|
564
|
+
|
|
565
|
+
Examples:
|
|
566
|
+
```
|
|
567
|
+
istr(1000).floor() ==> 1000 # divisible_by is 1 by default
|
|
568
|
+
istr(1000).floor(2) ==> 1000
|
|
569
|
+
istr(1000).floor(3) ==> 999
|
|
570
|
+
```
|
|
571
|
+
It is also possible to use the ceil method for floats or ints:
|
|
572
|
+
```
|
|
573
|
+
istr.floor(1000.2) ==> 1000
|
|
574
|
+
istr.floor(1000.2, 2) ==> 1000
|
|
575
|
+
istr.floor(1000.2, 3 ==> 999
|
|
576
|
+
```
|
|
577
|
+
|
|
538
578
|
#### enumerate with istrs
|
|
539
579
|
|
|
540
580
|
The `istr.enumerate` class method can be used just as the built-in enumerate function.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.1.
|
|
8
|
+
__version__ = "1.1.30"
|
|
9
9
|
import functools
|
|
10
10
|
import itertools
|
|
11
11
|
import types
|
|
@@ -677,6 +677,22 @@ class istr(str):
|
|
|
677
677
|
|
|
678
678
|
def reversed(self):
|
|
679
679
|
return self[::-1]
|
|
680
|
+
|
|
681
|
+
def ceil(self, divisible_by=1):
|
|
682
|
+
if divisible_by<=0:
|
|
683
|
+
raise ValueError(f"step has to be >0, not {divisible_by}")
|
|
684
|
+
if divisible_by!=int(divisible_by):
|
|
685
|
+
raise ValueError(f"step has to be an integer value, not {divisible_by}")
|
|
686
|
+
n = istr.interpret_as_float(self)
|
|
687
|
+
return istr((math.ceil(n/divisible_by))*divisible_by)
|
|
688
|
+
|
|
689
|
+
def floor(self, divisible_by=1):
|
|
690
|
+
if divisible_by<=0:
|
|
691
|
+
raise ValueError(f"step has to be >0, not {divisible_by}")
|
|
692
|
+
if divisible_by!=int(divisible_by):
|
|
693
|
+
raise ValueError(f"step has to be an integer value, not {divisible_by}")
|
|
694
|
+
return istr((math.floor(self/divisible_by))*divisible_by)
|
|
695
|
+
|
|
680
696
|
|
|
681
697
|
def interpret_as_int(self):
|
|
682
698
|
if isinstance(self, istr):
|
|
@@ -687,6 +703,16 @@ class istr(str):
|
|
|
687
703
|
n = int(self)
|
|
688
704
|
return n
|
|
689
705
|
|
|
706
|
+
|
|
707
|
+
def interpret_as_float(self):
|
|
708
|
+
if isinstance(self, istr):
|
|
709
|
+
if not self.is_int():
|
|
710
|
+
raise TypeError(f"not interpretable as float: {self._frepr(self)}")
|
|
711
|
+
n = self._as_int
|
|
712
|
+
else:
|
|
713
|
+
n = float(self)
|
|
714
|
+
return n
|
|
715
|
+
|
|
690
716
|
def _str_method(self, name, *args, **kwargs):
|
|
691
717
|
return self.__class__(getattr(super(), name)(*args, **kwargs))
|
|
692
718
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.30
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -548,6 +548,46 @@ istr('0456')[::-1] ==> istr('6540')
|
|
|
548
548
|
> istr(-456).reversed() + 3 ==> TypeError
|
|
549
549
|
> ```
|
|
550
550
|
|
|
551
|
+
|
|
552
|
+
#### ceil
|
|
553
|
+
|
|
554
|
+
The `istr.ceil` method can be used to find the smallest integer, divisible by a given number (divisible_by), greater than or equal to the value.
|
|
555
|
+
This can be useful to step through all multiples of n, >= m, like:
|
|
556
|
+
|
|
557
|
+
```
|
|
558
|
+
for i in istr.range(istr(1000/3, 10000, 3)) ==> # 1002, 1005, ... 9999
|
|
559
|
+
for i in istr.count(int(istr,ceil(1000/3)), 3)) ==> 1002, 1005, ...
|
|
560
|
+
```
|
|
561
|
+
Examples:
|
|
562
|
+
```
|
|
563
|
+
istr(1000).ceil() ==> 1000 # divisible_by is 1 by default
|
|
564
|
+
istr(1000).ceil(2) ==> 1000
|
|
565
|
+
istr(1000).ceil(3) ==> 1002
|
|
566
|
+
```
|
|
567
|
+
It is also possible to use the ceil method for floats or ints:
|
|
568
|
+
```
|
|
569
|
+
istr.ceil(1000.2) ==> 1001
|
|
570
|
+
istr.ceil(1000.2, 2) ==> 1002
|
|
571
|
+
istr.ceil(1000.2, 3 ==> 1002
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
#### floor
|
|
575
|
+
|
|
576
|
+
The `istr.floor` method can be used to find the largest integer, divisible by a given number (divisible_by), smaller than or equal to the value.
|
|
577
|
+
|
|
578
|
+
Examples:
|
|
579
|
+
```
|
|
580
|
+
istr(1000).floor() ==> 1000 # divisible_by is 1 by default
|
|
581
|
+
istr(1000).floor(2) ==> 1000
|
|
582
|
+
istr(1000).floor(3) ==> 999
|
|
583
|
+
```
|
|
584
|
+
It is also possible to use the ceil method for floats or ints:
|
|
585
|
+
```
|
|
586
|
+
istr.floor(1000.2) ==> 1000
|
|
587
|
+
istr.floor(1000.2, 2) ==> 1000
|
|
588
|
+
istr.floor(1000.2, 3 ==> 999
|
|
589
|
+
```
|
|
590
|
+
|
|
551
591
|
#### enumerate with istrs
|
|
552
592
|
|
|
553
593
|
The `istr.enumerate` class method can be used just as the built-in enumerate function.
|
|
@@ -987,7 +987,24 @@ def test_decompose():
|
|
|
987
987
|
with pytest.raises(ValueError):
|
|
988
988
|
istr(123).decompose("xy1")
|
|
989
989
|
|
|
990
|
-
|
|
990
|
+
def test_ceil():
|
|
991
|
+
assert istr(1000).ceil()==1000
|
|
992
|
+
assert istr(1000).ceil(1)==1000
|
|
993
|
+
assert istr(1000).ceil(2)==1000
|
|
994
|
+
assert istr(1000).ceil(3)==1002
|
|
995
|
+
assert istr.ceil(1000)==1000
|
|
996
|
+
assert istr.ceil(1000,1)==1000
|
|
997
|
+
assert istr.ceil(1000.2,1).equals(istr(1001))
|
|
998
|
+
|
|
999
|
+
def test_floor():
|
|
1000
|
+
assert istr(1000).floor()==1000
|
|
1001
|
+
assert istr(1000).floor(1)==1000
|
|
1002
|
+
assert istr(1000).floor(2)==1000
|
|
1003
|
+
assert istr(1000).floor(3)==999
|
|
1004
|
+
assert istr.floor(1000)==1000
|
|
1005
|
+
assert istr.floor(1000,1)==1000
|
|
1006
|
+
assert istr.floor(1000.2,1).equals(istr(1000))
|
|
1007
|
+
|
|
991
1008
|
def test_compose():
|
|
992
1009
|
global x, y, z, _
|
|
993
1010
|
x = 1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|