pygenutils 16.2.3__tar.gz → 16.2.4__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.
- {pygenutils-16.2.3/pygenutils.egg-info → pygenutils-16.2.4}/PKG-INFO +1 -1
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/__init__.py +1 -1
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/number_bases/base_converters.py +37 -18
- {pygenutils-16.2.3 → pygenutils-16.2.4/pygenutils.egg-info}/PKG-INFO +1 -1
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pyproject.toml +1 -1
- {pygenutils-16.2.3 → pygenutils-16.2.4}/LICENSE +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/MANIFEST.in +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/README.md +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/conversions.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/data_manipulation.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/maths.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/arrays_and_lists/patterns.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/audio_and_video/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/audio_and_video/audio_and_video_manipulation.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/audio_and_video/merge_audio_and_video.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/audio_and_video/merge_audio_or_video.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/audio_and_video/trim_media.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/dictionaries/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/dictionaries/dict_handler.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/dictionaries/dict_operators.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/number_bases/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/number_bases/binary_operations.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/number_bases/bitwise_operators.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/number_bases/mathematical_utils.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/operative_systems/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/operative_systems/os_operations.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/sets_and_intervals/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/sets_and_intervals/interval_handler.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/sets_and_intervals/sets_handler.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/strings/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/strings/string_handler.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/strings/text_formatters.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/__init__.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/calendar_utils.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/countdown.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/date_and_time_maths.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/date_and_time_utils.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/program_snippet_exec_timers.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/time_formatters.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/time_utils.py +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils.egg-info/SOURCES.txt +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils.egg-info/dependency_links.txt +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils.egg-info/requires.txt +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils.egg-info/top_level.txt +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/setup.cfg +0 -0
- {pygenutils-16.2.3 → pygenutils-16.2.4}/setup.py +0 -0
|
@@ -92,7 +92,7 @@ def _check_input_int(x):
|
|
|
92
92
|
# Procedure checker #
|
|
93
93
|
#-#-#-#-#-#-#-#-#-#-#
|
|
94
94
|
|
|
95
|
-
def _procedure_checker(arg):
|
|
95
|
+
def _procedure_checker(arg, procedure_opts):
|
|
96
96
|
"""
|
|
97
97
|
Checks if the provided procedure is valid.
|
|
98
98
|
|
|
@@ -105,8 +105,8 @@ def _procedure_checker(arg):
|
|
|
105
105
|
------
|
|
106
106
|
ValueError : If the procedure is not valid.
|
|
107
107
|
"""
|
|
108
|
-
if arg not in
|
|
109
|
-
raise ValueError(f"Unsupported procedure. Choose one from {
|
|
108
|
+
if arg not in procedure_opts:
|
|
109
|
+
raise ValueError(f"Unsupported procedure. Choose one from {procedure_opts}.")
|
|
110
110
|
|
|
111
111
|
# Frequently used bases #
|
|
112
112
|
#-----------------------#
|
|
@@ -130,15 +130,12 @@ def dec2bin_basic(n):
|
|
|
130
130
|
The binary representation of the input number.
|
|
131
131
|
"""
|
|
132
132
|
n_checked = _check_input_int(n)
|
|
133
|
-
b = ''
|
|
134
|
-
while
|
|
133
|
+
b = "" # or '_bin', so that we understand the var name better?
|
|
134
|
+
while n_checked >= 1:
|
|
135
135
|
floordiv, mod = divmod(n_checked,2)
|
|
136
136
|
b += str(mod)
|
|
137
|
-
if floordiv == 0:
|
|
138
|
-
break
|
|
139
137
|
n_checked //= 2
|
|
140
|
-
|
|
141
|
-
return b_actual
|
|
138
|
+
return b[::-1]
|
|
142
139
|
|
|
143
140
|
# Advanced #
|
|
144
141
|
#-#-#-#-#-#-
|
|
@@ -162,7 +159,7 @@ def base2bin(n, procedure="format_string", zero_pad=4):
|
|
|
162
159
|
str
|
|
163
160
|
The binary representation of the input number.
|
|
164
161
|
"""
|
|
165
|
-
_procedure_checker(procedure)
|
|
162
|
+
_procedure_checker(procedure, NUMBER_CONVERSION_PROCEDURE_OPTS)
|
|
166
163
|
|
|
167
164
|
if procedure == "default":
|
|
168
165
|
n_bin = bin(n)
|
|
@@ -188,7 +185,7 @@ def base2oct(n, procedure="format_string", zero_pad=4):
|
|
|
188
185
|
str
|
|
189
186
|
The octal representation of the input number.
|
|
190
187
|
"""
|
|
191
|
-
_procedure_checker(procedure)
|
|
188
|
+
_procedure_checker(procedure, NUMBER_CONVERSION_PROCEDURE_OPTS)
|
|
192
189
|
|
|
193
190
|
if procedure == "default":
|
|
194
191
|
n_oct = oct(n)
|
|
@@ -214,7 +211,7 @@ def base2hex(n, procedure="format_string", zero_pad=4):
|
|
|
214
211
|
str
|
|
215
212
|
The hexadecimal representation of the input number.
|
|
216
213
|
"""
|
|
217
|
-
_procedure_checker(procedure)
|
|
214
|
+
_procedure_checker(procedure, NUMBER_CONVERSION_PROCEDURE_OPTS)
|
|
218
215
|
|
|
219
216
|
if procedure == "default":
|
|
220
217
|
if isinstance(n, float):
|
|
@@ -246,7 +243,7 @@ def bin2dec(n_bin):
|
|
|
246
243
|
n = int(n_bin, base=2)
|
|
247
244
|
return n
|
|
248
245
|
|
|
249
|
-
def bin2dec_basic(b):
|
|
246
|
+
def bin2dec_basic(b, procedure="loop"):
|
|
250
247
|
"""
|
|
251
248
|
Converts a binary number to decimal, using mathematical operations
|
|
252
249
|
by definition (hence the name 'basic').
|
|
@@ -257,6 +254,12 @@ def bin2dec_basic(b):
|
|
|
257
254
|
The binary number as a string.
|
|
258
255
|
It can contain the 'b' or '0b' prefix. If so, the function
|
|
259
256
|
will take into account the string without the prefix.
|
|
257
|
+
procedure : str
|
|
258
|
+
The procedure to use for conversion. Options are:
|
|
259
|
+
- 'list_comprehension': Uses a list comprehension with enumerate for a more
|
|
260
|
+
functional approach. Might be more memory intensive for large numbers.
|
|
261
|
+
- 'loop': Uses a traditional for loop with enumerate. More memory efficient
|
|
262
|
+
as it doesn't create an intermediate list.
|
|
260
263
|
|
|
261
264
|
Returns
|
|
262
265
|
-------
|
|
@@ -264,13 +267,28 @@ def bin2dec_basic(b):
|
|
|
264
267
|
The decimal equivalent of the binary number.
|
|
265
268
|
"""
|
|
266
269
|
|
|
270
|
+
# Validations #
|
|
271
|
+
###############
|
|
272
|
+
|
|
273
|
+
# Procedure #
|
|
274
|
+
_procedure_checker(procedure, BIN2DEC_PROCEDURE_OPTS)
|
|
275
|
+
|
|
276
|
+
# Number input #
|
|
267
277
|
b_checked = _check_input_binary(b)
|
|
268
278
|
lb = len(b_checked)
|
|
269
279
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
# Calculation #
|
|
281
|
+
###############
|
|
282
|
+
|
|
283
|
+
if procedure == "list_comprehension":
|
|
284
|
+
summands_iter = [int(b_checked[i]) * 2 ** pos for pos, i in enumerate(range(lb-1,-1,-1))]
|
|
285
|
+
res = sum(summands_iter)
|
|
286
|
+
|
|
287
|
+
elif procedure == "loop":
|
|
288
|
+
res = 0
|
|
289
|
+
for pos, i in enumerate(range(lb-1,-1,-1)):
|
|
290
|
+
res += int(b_checked[i]) * 2 ** pos
|
|
291
|
+
return res
|
|
274
292
|
|
|
275
293
|
|
|
276
294
|
def oct2dec(n_oct):
|
|
@@ -360,4 +378,5 @@ def convert_among_arbitraries(x, base):
|
|
|
360
378
|
# Parameters and constants #
|
|
361
379
|
#--------------------------#
|
|
362
380
|
|
|
363
|
-
|
|
381
|
+
BIN2DEC_PROCEDURE_OPTS = ['list_comprehension', 'loop']
|
|
382
|
+
NUMBER_CONVERSION_PROCEDURE_OPTS = ['default', 'format_string']
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pygenutils"
|
|
7
|
-
version = "16.2.
|
|
7
|
+
version = "16.2.4"
|
|
8
8
|
license = {file = "LICENSE"}
|
|
9
9
|
description = "A comprehensive Python utility library for general-purpose and specialised tasks"
|
|
10
10
|
keywords = ["utilities", "python", "general-purpose", "file handling", "string processing"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/audio_and_video/audio_and_video_manipulation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pygenutils-16.2.3 → pygenutils-16.2.4}/pygenutils/time_handling/program_snippet_exec_timers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|