istr-python 1.1.45__tar.gz → 1.2.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.45
3
+ Version: 1.2.0
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
@@ -339,17 +339,16 @@ several other types:
339
339
  istr({0, 1, 4}) ==> {istr('4'), istr('0'), istr('1')} # or similar
340
340
  ```
341
341
 
342
- - if a range, an istr.range instance will be returned
342
+ - if a range, a generator that yields istr-s will be returned
343
343
 
344
344
  ```
345
- istr(range(3)) ==> istr.range(3)
346
- list(istr(range(3))) ==> [istr('0'), istr('1'), istr('2')]
347
- len(istr(range(3))) ==> 3
345
+ list(istr(range(3))) ==> [istr('0', istr('1', istr('2')]
346
+
348
347
  ```
349
348
 
350
- - if an istr.range instance, the same istr.range will be returned
349
+ - if an istr.range instance, the generator will be propagated
351
350
  ```
352
- istr(istr.range(5)) ==> istr.range(5)
351
+ list(istr(istr.range(3))) ==> [istr('0', istr('1', istr('2')]
353
352
  ```
354
353
 
355
354
 
@@ -384,6 +383,15 @@ On top of this, `istr.range` support a keyword parameter `distinct`, to return a
384
383
 
385
384
  For `istr.range(length=..., distict=True)` the generation is optimized (not just checking each possible value).
386
385
 
386
+ It is also possible to specify an exclude parameter, with which any generated value will be discarded if it contains a character in exclude. E.g:
387
+
388
+ ```
389
+ for i in istr.range(length=5, distinct=True):
390
+ if ...:
391
+ for j in istr.range(length=2, distinct=True, exclude=i):
392
+ ...
393
+ ```
394
+
387
395
  #### square root, cubic root and nth root
388
396
  The methods `sqrt`, `cbrt`, `nth_root`provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default `istr('0')` will be returned.
389
397
  ```
@@ -1142,11 +1150,8 @@ This will print
1142
1150
  ?
1143
1151
  ```
1144
1152
 
1145
- ##### Note
1146
1153
  >
1147
- > The way an `istr` is represented is determined at initialization.
1148
-
1149
- It is also possible to set the repr mode without a context manager:
1154
+ > It is also possible to set the repr mode without a context manager:
1150
1155
 
1151
1156
  ```
1152
1157
  istr.repr_mode('str')
@@ -1163,48 +1168,6 @@ print(repr(istr.repr_mode()))
1163
1168
  ```
1164
1169
  will output `istr`.
1165
1170
 
1166
- #### Changing the base system
1167
-
1168
- By default, `istr` works in base 10. However it is possible to change the base system with the `istr.base()` context manager / method.
1169
-
1170
- Any base between 2 and 36 may be used.
1171
-
1172
- Note that the integer is **always** stored in base 10 mode, but the string
1173
- representation will reflect the chosen base (at time of initialization).
1174
-
1175
- Some examples:
1176
- ```
1177
- with istr.base(16):
1178
- a = istr('7fff')
1179
- print(int(a))
1180
-
1181
- b = istr(127)
1182
- print(repr(b))
1183
- ```
1184
- This will result in
1185
- ```
1186
- 32767
1187
- istr('7F')
1188
- ```
1189
- All calculations are done in the decimal 10 base system.
1190
-
1191
- Note that the way an `istr` is interpreted is determined at initialization.
1192
-
1193
- It is also possible to set the repr mode without a context manager:
1194
- ```
1195
- istr.base(16)
1196
- print(int(istr('7fff')))
1197
- ```
1198
- This will print
1199
- ```
1200
- 32767
1201
- ```
1202
- Finally, the current base can be queried with `istr.base()`, so upon start:
1203
- ```
1204
- print(istr.base())
1205
- ```
1206
- will result in `10`.
1207
-
1208
1171
  #### Changing the format of the string
1209
1172
 
1210
1173
  When an istr is initialized with a string the istr will be always stored as such.
@@ -1255,9 +1218,8 @@ istr('123')
1255
1218
  istr('1234')
1256
1219
  ```
1257
1220
 
1258
- ##### Note
1259
- >
1260
- > For bases other than 10, the string will never be reformatted!
1221
+
1222
+
1261
1223
 
1262
1224
  ### Overview of operations
1263
1225
 
@@ -1269,32 +1231,31 @@ operator/function int str Example
1269
1231
  + x istr(20) + 3 ==> istr('23')
1270
1232
  _ x istr(20) - 3 ==> istr('17')
1271
1233
  * x istr(20) * 3 ==> istr('60')
1272
- / x istr(20) / 3 ==> istr('6')
1273
- // x istr(20) // 3 ==> istr('6')
1274
- % x istr(20) % 3 ==> istr('2')
1275
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1276
- ** x istr(2) ** 3 ==> istr('8')
1277
- <=, <, >, >= x istr('100') > istr('2') ==> True
1278
- abs x abs(istr(-20)) ==> istr('20')
1279
- int x int(istr("20")) ==> 20
1280
- float x float(istr("20")) ==> 20.0
1281
- complex x complex(istr("20")) ==> (20+0j)
1282
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1283
- bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1284
- @ x istr(20) @ 3 ==> istr('202020')
1285
- | x istr(20) | '5' ==> istr('205')
1286
- slicing x istr(12345)[1:3] ==> istr('23')
1287
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1288
- len x len(istr(' 20 ')) ==> 4
1289
- count x istr(100).count(0) ==> 2
1290
- istr.count(100) ==> istr('100'), istr('101'). istr('102'), ...
1291
- index x istr(' 100 ').index('0') ==> 2
1292
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
1293
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
1294
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1234
+ / x istr(20) / 3 ==> istr('6')
1235
+ // x istr(20) // 3 ==> istr('6')
1236
+ % x istr(20) % 3 ==> istr('2')
1237
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1238
+ ** x istr(2) ** 3 ==> istr('8')
1239
+ <=, <, >, >= x istr('100') > istr('2') ==> True
1240
+ abs x abs(istr(-20)) ==> istr('20')
1241
+ int x int(istr("20")) ==> 20
1242
+ float x float(istr("20")) ==> 20.0
1243
+ complex x complex(istr("20")) ==> (20+0j)
1244
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1245
+ bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1246
+ @ x istr(20) @ 3 ==> istr('202020')
1247
+ | x istr(20) | '5' ==> istr('205')
1248
+ slicing x istr(12345)[1:3] ==> istr('23')
1249
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1250
+ len x len(istr(' 20 ')) ==> 4
1251
+ count x istr(100).count(0) ==> 2
1252
+ istr.count(100) ==> istr('100'), istr('101'). ...
1253
+ index x istr(' 100 ').index('0') ==> 2
1254
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
1255
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
1256
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1295
1257
  istr('aAbBcC').islower() ==> False
1296
1258
  istr(' abc ').strip() ==> istr('abc')
1297
- ...
1298
1259
  -----------------------------------------------------------------------------------------
1299
1260
  *) str is applied if is_int() is False
1300
1261
  ```
@@ -326,17 +326,16 @@ several other types:
326
326
  istr({0, 1, 4}) ==> {istr('4'), istr('0'), istr('1')} # or similar
327
327
  ```
328
328
 
329
- - if a range, an istr.range instance will be returned
329
+ - if a range, a generator that yields istr-s will be returned
330
330
 
331
331
  ```
332
- istr(range(3)) ==> istr.range(3)
333
- list(istr(range(3))) ==> [istr('0'), istr('1'), istr('2')]
334
- len(istr(range(3))) ==> 3
332
+ list(istr(range(3))) ==> [istr('0', istr('1', istr('2')]
333
+
335
334
  ```
336
335
 
337
- - if an istr.range instance, the same istr.range will be returned
336
+ - if an istr.range instance, the generator will be propagated
338
337
  ```
339
- istr(istr.range(5)) ==> istr.range(5)
338
+ list(istr(istr.range(3))) ==> [istr('0', istr('1', istr('2')]
340
339
  ```
341
340
 
342
341
 
@@ -371,6 +370,15 @@ On top of this, `istr.range` support a keyword parameter `distinct`, to return a
371
370
 
372
371
  For `istr.range(length=..., distict=True)` the generation is optimized (not just checking each possible value).
373
372
 
373
+ It is also possible to specify an exclude parameter, with which any generated value will be discarded if it contains a character in exclude. E.g:
374
+
375
+ ```
376
+ for i in istr.range(length=5, distinct=True):
377
+ if ...:
378
+ for j in istr.range(length=2, distinct=True, exclude=i):
379
+ ...
380
+ ```
381
+
374
382
  #### square root, cubic root and nth root
375
383
  The methods `sqrt`, `cbrt`, `nth_root`provide the square root, cubic root and nth root of an istr. If there is no integer root, the fallback value (default `istr('0')` will be returned.
376
384
  ```
@@ -1129,11 +1137,8 @@ This will print
1129
1137
  ?
1130
1138
  ```
1131
1139
 
1132
- ##### Note
1133
1140
  >
1134
- > The way an `istr` is represented is determined at initialization.
1135
-
1136
- It is also possible to set the repr mode without a context manager:
1141
+ > It is also possible to set the repr mode without a context manager:
1137
1142
 
1138
1143
  ```
1139
1144
  istr.repr_mode('str')
@@ -1150,48 +1155,6 @@ print(repr(istr.repr_mode()))
1150
1155
  ```
1151
1156
  will output `istr`.
1152
1157
 
1153
- #### Changing the base system
1154
-
1155
- By default, `istr` works in base 10. However it is possible to change the base system with the `istr.base()` context manager / method.
1156
-
1157
- Any base between 2 and 36 may be used.
1158
-
1159
- Note that the integer is **always** stored in base 10 mode, but the string
1160
- representation will reflect the chosen base (at time of initialization).
1161
-
1162
- Some examples:
1163
- ```
1164
- with istr.base(16):
1165
- a = istr('7fff')
1166
- print(int(a))
1167
-
1168
- b = istr(127)
1169
- print(repr(b))
1170
- ```
1171
- This will result in
1172
- ```
1173
- 32767
1174
- istr('7F')
1175
- ```
1176
- All calculations are done in the decimal 10 base system.
1177
-
1178
- Note that the way an `istr` is interpreted is determined at initialization.
1179
-
1180
- It is also possible to set the repr mode without a context manager:
1181
- ```
1182
- istr.base(16)
1183
- print(int(istr('7fff')))
1184
- ```
1185
- This will print
1186
- ```
1187
- 32767
1188
- ```
1189
- Finally, the current base can be queried with `istr.base()`, so upon start:
1190
- ```
1191
- print(istr.base())
1192
- ```
1193
- will result in `10`.
1194
-
1195
1158
  #### Changing the format of the string
1196
1159
 
1197
1160
  When an istr is initialized with a string the istr will be always stored as such.
@@ -1242,9 +1205,8 @@ istr('123')
1242
1205
  istr('1234')
1243
1206
  ```
1244
1207
 
1245
- ##### Note
1246
- >
1247
- > For bases other than 10, the string will never be reformatted!
1208
+
1209
+
1248
1210
 
1249
1211
  ### Overview of operations
1250
1212
 
@@ -1256,32 +1218,31 @@ operator/function int str Example
1256
1218
  + x istr(20) + 3 ==> istr('23')
1257
1219
  _ x istr(20) - 3 ==> istr('17')
1258
1220
  * x istr(20) * 3 ==> istr('60')
1259
- / x istr(20) / 3 ==> istr('6')
1260
- // x istr(20) // 3 ==> istr('6')
1261
- % x istr(20) % 3 ==> istr('2')
1262
- divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1263
- ** x istr(2) ** 3 ==> istr('8')
1264
- <=, <, >, >= x istr('100') > istr('2') ==> True
1265
- abs x abs(istr(-20)) ==> istr('20')
1266
- int x int(istr("20")) ==> 20
1267
- float x float(istr("20")) ==> 20.0
1268
- complex x complex(istr("20")) ==> (20+0j)
1269
- == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1270
- bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1271
- @ x istr(20) @ 3 ==> istr('202020')
1272
- | x istr(20) | '5' ==> istr('205')
1273
- slicing x istr(12345)[1:3] ==> istr('23')
1274
- iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1275
- len x len(istr(' 20 ')) ==> 4
1276
- count x istr(100).count(0) ==> 2
1277
- istr.count(100) ==> istr('100'), istr('101'). istr('102'), ...
1278
- index x istr(' 100 ').index('0') ==> 2
1279
- split x istr('1 2').split() ==> (istr('1'), istr('2'))
1280
- string format x f"|{istr(1234):6}|" ==> '|1234 |'
1281
- other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1221
+ / x istr(20) / 3 ==> istr('6')
1222
+ // x istr(20) // 3 ==> istr('6')
1223
+ % x istr(20) % 3 ==> istr('2')
1224
+ divmod x divmod(istr(20), 3) ==> (istr('6'), istr('2'))
1225
+ ** x istr(2) ** 3 ==> istr('8')
1226
+ <=, <, >, >= x istr('100') > istr('2') ==> True
1227
+ abs x abs(istr(-20)) ==> istr('20')
1228
+ int x int(istr("20")) ==> 20
1229
+ float x float(istr("20")) ==> 20.0
1230
+ complex x complex(istr("20")) ==> (20+0j)
1231
+ == x x istr(20) == 20 ==> True | istr(20) == '20' ==> True
1232
+ bool x x *) bool(istr(' 0 ')) ==> False | bool(istr('')) ==> False
1233
+ @ x istr(20) @ 3 ==> istr('202020')
1234
+ | x istr(20) | '5' ==> istr('205')
1235
+ slicing x istr(12345)[1:3] ==> istr('23')
1236
+ iterate x [x for x in istr(20)] ==> [istr('2'), istr('0')]
1237
+ len x len(istr(' 20 ')) ==> 4
1238
+ count x istr(100).count(0) ==> 2
1239
+ istr.count(100) ==> istr('100'), istr('101'). ...
1240
+ index x istr(' 100 ').index('0') ==> 2
1241
+ split x istr('1 2').split() ==> (istr('1'), istr('2'))
1242
+ string format x f"|{istr(1234):6}|" ==> '|1234 |'
1243
+ other string methods x istr('aAbBcC').lower() ==> istr('aabbcc')
1282
1244
  istr('aAbBcC').islower() ==> False
1283
1245
  istr(' abc ').strip() ==> istr('abc')
1284
- ...
1285
1246
  -----------------------------------------------------------------------------------------
1286
1247
  *) str is applied if is_int() is False
1287
1248
  ```