lkj 0.1.44__tar.gz → 0.1.46__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.
- {lkj-0.1.44 → lkj-0.1.46}/PKG-INFO +101 -1
- {lkj-0.1.44 → lkj-0.1.46}/README.md +100 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/strings.py +6 -8
- {lkj-0.1.44 → lkj-0.1.46}/lkj.egg-info/PKG-INFO +101 -1
- {lkj-0.1.44 → lkj-0.1.46}/setup.cfg +1 -1
- {lkj-0.1.44 → lkj-0.1.46}/LICENSE +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/__init__.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/chunking.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/dicts.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/filesys.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/funcs.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/importing.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/iterables.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/loggers.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj/misc.py +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj.egg-info/SOURCES.txt +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj.egg-info/dependency_links.txt +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj.egg-info/not-zip-safe +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/lkj.egg-info/top_level.txt +0 -0
- {lkj-0.1.44 → lkj-0.1.46}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lkj
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.46
|
|
4
4
|
Summary: A dump of homeless useful utils
|
|
5
5
|
Home-page: https://github.com/thorwhalen/lkj
|
|
6
6
|
Author: Thor Whalen
|
|
@@ -167,3 +167,103 @@ import_object(dot_path: str)
|
|
|
167
167
|
>>> f is join
|
|
168
168
|
True
|
|
169
169
|
```
|
|
170
|
+
|
|
171
|
+
## Pretty Printing Lists
|
|
172
|
+
|
|
173
|
+
The `print_list` function provides flexible, human-friendly ways to display lists and collections. It supports multiple display styles and can be used in several ways.
|
|
174
|
+
|
|
175
|
+
### Basic Usage
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from lkj.strings import print_list
|
|
179
|
+
|
|
180
|
+
items = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig']
|
|
181
|
+
|
|
182
|
+
# Different display styles
|
|
183
|
+
print_list(items, style='wrapped') # Automatic line wrapping
|
|
184
|
+
print_list(items, style='columns') # Column format
|
|
185
|
+
print_list(items, style='numbered') # Numbered list
|
|
186
|
+
print_list(items, style='bullet') # Bullet points
|
|
187
|
+
print_list(items, style='compact') # All on one line
|
|
188
|
+
print_list(items, style='table') # Table format
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Direct Usage with Customization
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
# Customize width, separators, and formatting
|
|
195
|
+
print_list(items, style='wrapped', max_width=40, sep=' | ')
|
|
196
|
+
print_list(items, style='columns', items_per_line=3)
|
|
197
|
+
print_list(items, style='numbered', line_prefix=' ')
|
|
198
|
+
print_list(items, style='bullet', show_count=False)
|
|
199
|
+
|
|
200
|
+
# Return string instead of printing
|
|
201
|
+
result = print_list(items, style='numbered', print_func=None)
|
|
202
|
+
print(result)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Partial Function Factory
|
|
206
|
+
|
|
207
|
+
When you don't specify the `items` parameter, `print_list` returns a partial function that you can reuse:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
# Create specialized printers
|
|
211
|
+
numbered_printer = print_list(style='numbered', show_count=False)
|
|
212
|
+
bullet_printer = print_list(style='bullet', print_func=None)
|
|
213
|
+
compact_printer = print_list(style='compact', max_width=60)
|
|
214
|
+
|
|
215
|
+
# Reuse with different data
|
|
216
|
+
numbered_printer(['a', 'b', 'c']) # Prints: 1. a\n2. b\n3. c
|
|
217
|
+
result = bullet_printer(['x', 'y', 'z']) # Returns: '• x\n• y\n• z'
|
|
218
|
+
compact_printer(['item1', 'item2']) # Prints: item1, item2
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Convenience Methods
|
|
222
|
+
|
|
223
|
+
The `print_list` object provides convenient pre-configured methods:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
# Quick access to common styles
|
|
227
|
+
print_list.compact(items) # Compact format, no count
|
|
228
|
+
print_list.wrapped(items) # Wrapped format, no count
|
|
229
|
+
print_list.columns(items) # Column format, no count
|
|
230
|
+
print_list.numbered(items) # Numbered format, no count
|
|
231
|
+
print_list.bullets(items) # Bullet format, no count
|
|
232
|
+
|
|
233
|
+
# Specialized methods
|
|
234
|
+
print_list.as_table(data) # Table with headers
|
|
235
|
+
print_list.summary(items) # Summary for long lists
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Advanced Examples
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
# Table with custom data
|
|
242
|
+
data = [['Name', 'Age', 'City'], ['Alice', 25, 'NYC'], ['Bob', 30, 'LA']]
|
|
243
|
+
print_list.as_table(data)
|
|
244
|
+
|
|
245
|
+
# Summary for long lists
|
|
246
|
+
long_list = list(range(100))
|
|
247
|
+
print_list.summary(long_list, max_items=6) # Shows: [0, 1, 2, ..., 97, 98, 99]
|
|
248
|
+
|
|
249
|
+
# Custom print function (e.g., for logging)
|
|
250
|
+
def my_logger(msg):
|
|
251
|
+
print(f"[LOG] {msg}")
|
|
252
|
+
|
|
253
|
+
print_list(items, style='bullet', print_func=my_logger)
|
|
254
|
+
|
|
255
|
+
# Combine partial with custom parameters
|
|
256
|
+
custom_compact = print_list(style='compact', sep=' | ')
|
|
257
|
+
custom_compact(items) # Prints: apple | banana | cherry | date | elderberry | fig
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Key Features
|
|
261
|
+
|
|
262
|
+
- **Multiple Styles**: `wrapped`, `columns`, `numbered`, `bullet`, `compact`, `table`
|
|
263
|
+
- **Flexible Output**: Print directly or return strings with `print_func=None`
|
|
264
|
+
- **Partial Functions**: Create reusable printers with pre-configured settings
|
|
265
|
+
- **Customizable**: Control width, separators, line prefixes, and more
|
|
266
|
+
- **Type Safe**: Uses `Literal` types for style validation
|
|
267
|
+
- **Self-Contained**: No external dependencies beyond Python standard library
|
|
268
|
+
|
|
269
|
+
The `print_list` function is perfect for debugging, logging, user interfaces, and any situation where you need to display lists in a readable format.
|
|
@@ -156,3 +156,103 @@ import_object(dot_path: str)
|
|
|
156
156
|
>>> f is join
|
|
157
157
|
True
|
|
158
158
|
```
|
|
159
|
+
|
|
160
|
+
## Pretty Printing Lists
|
|
161
|
+
|
|
162
|
+
The `print_list` function provides flexible, human-friendly ways to display lists and collections. It supports multiple display styles and can be used in several ways.
|
|
163
|
+
|
|
164
|
+
### Basic Usage
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from lkj.strings import print_list
|
|
168
|
+
|
|
169
|
+
items = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig']
|
|
170
|
+
|
|
171
|
+
# Different display styles
|
|
172
|
+
print_list(items, style='wrapped') # Automatic line wrapping
|
|
173
|
+
print_list(items, style='columns') # Column format
|
|
174
|
+
print_list(items, style='numbered') # Numbered list
|
|
175
|
+
print_list(items, style='bullet') # Bullet points
|
|
176
|
+
print_list(items, style='compact') # All on one line
|
|
177
|
+
print_list(items, style='table') # Table format
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Direct Usage with Customization
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
# Customize width, separators, and formatting
|
|
184
|
+
print_list(items, style='wrapped', max_width=40, sep=' | ')
|
|
185
|
+
print_list(items, style='columns', items_per_line=3)
|
|
186
|
+
print_list(items, style='numbered', line_prefix=' ')
|
|
187
|
+
print_list(items, style='bullet', show_count=False)
|
|
188
|
+
|
|
189
|
+
# Return string instead of printing
|
|
190
|
+
result = print_list(items, style='numbered', print_func=None)
|
|
191
|
+
print(result)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Partial Function Factory
|
|
195
|
+
|
|
196
|
+
When you don't specify the `items` parameter, `print_list` returns a partial function that you can reuse:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
# Create specialized printers
|
|
200
|
+
numbered_printer = print_list(style='numbered', show_count=False)
|
|
201
|
+
bullet_printer = print_list(style='bullet', print_func=None)
|
|
202
|
+
compact_printer = print_list(style='compact', max_width=60)
|
|
203
|
+
|
|
204
|
+
# Reuse with different data
|
|
205
|
+
numbered_printer(['a', 'b', 'c']) # Prints: 1. a\n2. b\n3. c
|
|
206
|
+
result = bullet_printer(['x', 'y', 'z']) # Returns: '• x\n• y\n• z'
|
|
207
|
+
compact_printer(['item1', 'item2']) # Prints: item1, item2
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Convenience Methods
|
|
211
|
+
|
|
212
|
+
The `print_list` object provides convenient pre-configured methods:
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
# Quick access to common styles
|
|
216
|
+
print_list.compact(items) # Compact format, no count
|
|
217
|
+
print_list.wrapped(items) # Wrapped format, no count
|
|
218
|
+
print_list.columns(items) # Column format, no count
|
|
219
|
+
print_list.numbered(items) # Numbered format, no count
|
|
220
|
+
print_list.bullets(items) # Bullet format, no count
|
|
221
|
+
|
|
222
|
+
# Specialized methods
|
|
223
|
+
print_list.as_table(data) # Table with headers
|
|
224
|
+
print_list.summary(items) # Summary for long lists
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Advanced Examples
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
# Table with custom data
|
|
231
|
+
data = [['Name', 'Age', 'City'], ['Alice', 25, 'NYC'], ['Bob', 30, 'LA']]
|
|
232
|
+
print_list.as_table(data)
|
|
233
|
+
|
|
234
|
+
# Summary for long lists
|
|
235
|
+
long_list = list(range(100))
|
|
236
|
+
print_list.summary(long_list, max_items=6) # Shows: [0, 1, 2, ..., 97, 98, 99]
|
|
237
|
+
|
|
238
|
+
# Custom print function (e.g., for logging)
|
|
239
|
+
def my_logger(msg):
|
|
240
|
+
print(f"[LOG] {msg}")
|
|
241
|
+
|
|
242
|
+
print_list(items, style='bullet', print_func=my_logger)
|
|
243
|
+
|
|
244
|
+
# Combine partial with custom parameters
|
|
245
|
+
custom_compact = print_list(style='compact', sep=' | ')
|
|
246
|
+
custom_compact(items) # Prints: apple | banana | cherry | date | elderberry | fig
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Key Features
|
|
250
|
+
|
|
251
|
+
- **Multiple Styles**: `wrapped`, `columns`, `numbered`, `bullet`, `compact`, `table`
|
|
252
|
+
- **Flexible Output**: Print directly or return strings with `print_func=None`
|
|
253
|
+
- **Partial Functions**: Create reusable printers with pre-configured settings
|
|
254
|
+
- **Customizable**: Control width, separators, line prefixes, and more
|
|
255
|
+
- **Type Safe**: Uses `Literal` types for style validation
|
|
256
|
+
- **Self-Contained**: No external dependencies beyond Python standard library
|
|
257
|
+
|
|
258
|
+
The `print_list` function is perfect for debugging, logging, user interfaces, and any situation where you need to display lists in a readable format.
|
|
@@ -741,7 +741,7 @@ def print_list(
|
|
|
741
741
|
sep: str = ", ",
|
|
742
742
|
line_prefix: str = "",
|
|
743
743
|
items_per_line=None,
|
|
744
|
-
show_count=
|
|
744
|
+
show_count: Union[bool, Callable[[int], str]] = False,
|
|
745
745
|
title=None,
|
|
746
746
|
print_func=print,
|
|
747
747
|
):
|
|
@@ -755,7 +755,7 @@ def print_list(
|
|
|
755
755
|
sep: Separator for items
|
|
756
756
|
line_prefix: Prefix for each line
|
|
757
757
|
items_per_line: For columns style, how many items per line
|
|
758
|
-
show_count: Whether to
|
|
758
|
+
show_count: Whether to prefix with the count of items
|
|
759
759
|
title: Optional title to display before the list
|
|
760
760
|
print_func: Function to use for printing. Defaults to print.
|
|
761
761
|
If None, returns the string instead of printing.
|
|
@@ -765,19 +765,16 @@ def print_list(
|
|
|
765
765
|
|
|
766
766
|
# Wrapped style (default)
|
|
767
767
|
>>> print_list(items, max_width=30)
|
|
768
|
-
List (6 items):
|
|
769
768
|
apple, banana, cherry, date,
|
|
770
769
|
elderberry, fig
|
|
771
770
|
|
|
772
771
|
# Columns style
|
|
773
772
|
>>> print_list(items, style="columns", items_per_line=3)
|
|
774
|
-
List (6 items):
|
|
775
773
|
apple banana cherry
|
|
776
774
|
date elderberry fig
|
|
777
775
|
|
|
778
776
|
# Numbered style
|
|
779
777
|
>>> print_list(items, style="numbered")
|
|
780
|
-
List (6 items):
|
|
781
778
|
1. apple
|
|
782
779
|
2. banana
|
|
783
780
|
3. cherry
|
|
@@ -787,7 +784,6 @@ def print_list(
|
|
|
787
784
|
|
|
788
785
|
# Bullet style
|
|
789
786
|
>>> print_list(items, style="bullet")
|
|
790
|
-
List (6 items):
|
|
791
787
|
• apple
|
|
792
788
|
• banana
|
|
793
789
|
• cherry
|
|
@@ -796,7 +792,7 @@ def print_list(
|
|
|
796
792
|
• fig
|
|
797
793
|
|
|
798
794
|
# Return string instead of printing
|
|
799
|
-
>>> result = print_list(items, style="numbered", print_func=None)
|
|
795
|
+
>>> result = print_list(items, style="numbered", print_func=None, show_count=True)
|
|
800
796
|
>>> print(result)
|
|
801
797
|
List (6 items):
|
|
802
798
|
1. apple
|
|
@@ -847,6 +843,8 @@ def print_list(
|
|
|
847
843
|
print_func=print_func,
|
|
848
844
|
)
|
|
849
845
|
items = list(items) # Convert to list if it's an iterable
|
|
846
|
+
if show_count is True:
|
|
847
|
+
show_count = lambda n_items: f"List ({n_items} items):"
|
|
850
848
|
|
|
851
849
|
# Handle print_func=None by using StringAppender
|
|
852
850
|
if print_func is None:
|
|
@@ -860,7 +858,7 @@ def print_list(
|
|
|
860
858
|
if title:
|
|
861
859
|
print_func(title)
|
|
862
860
|
elif show_count:
|
|
863
|
-
print_func(
|
|
861
|
+
print_func(show_count(len(items)))
|
|
864
862
|
|
|
865
863
|
if not items:
|
|
866
864
|
print_func(f"{line_prefix}(empty list)")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lkj
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.46
|
|
4
4
|
Summary: A dump of homeless useful utils
|
|
5
5
|
Home-page: https://github.com/thorwhalen/lkj
|
|
6
6
|
Author: Thor Whalen
|
|
@@ -167,3 +167,103 @@ import_object(dot_path: str)
|
|
|
167
167
|
>>> f is join
|
|
168
168
|
True
|
|
169
169
|
```
|
|
170
|
+
|
|
171
|
+
## Pretty Printing Lists
|
|
172
|
+
|
|
173
|
+
The `print_list` function provides flexible, human-friendly ways to display lists and collections. It supports multiple display styles and can be used in several ways.
|
|
174
|
+
|
|
175
|
+
### Basic Usage
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from lkj.strings import print_list
|
|
179
|
+
|
|
180
|
+
items = ['apple', 'banana', 'cherry', 'date', 'elderberry', 'fig']
|
|
181
|
+
|
|
182
|
+
# Different display styles
|
|
183
|
+
print_list(items, style='wrapped') # Automatic line wrapping
|
|
184
|
+
print_list(items, style='columns') # Column format
|
|
185
|
+
print_list(items, style='numbered') # Numbered list
|
|
186
|
+
print_list(items, style='bullet') # Bullet points
|
|
187
|
+
print_list(items, style='compact') # All on one line
|
|
188
|
+
print_list(items, style='table') # Table format
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Direct Usage with Customization
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
# Customize width, separators, and formatting
|
|
195
|
+
print_list(items, style='wrapped', max_width=40, sep=' | ')
|
|
196
|
+
print_list(items, style='columns', items_per_line=3)
|
|
197
|
+
print_list(items, style='numbered', line_prefix=' ')
|
|
198
|
+
print_list(items, style='bullet', show_count=False)
|
|
199
|
+
|
|
200
|
+
# Return string instead of printing
|
|
201
|
+
result = print_list(items, style='numbered', print_func=None)
|
|
202
|
+
print(result)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Partial Function Factory
|
|
206
|
+
|
|
207
|
+
When you don't specify the `items` parameter, `print_list` returns a partial function that you can reuse:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
# Create specialized printers
|
|
211
|
+
numbered_printer = print_list(style='numbered', show_count=False)
|
|
212
|
+
bullet_printer = print_list(style='bullet', print_func=None)
|
|
213
|
+
compact_printer = print_list(style='compact', max_width=60)
|
|
214
|
+
|
|
215
|
+
# Reuse with different data
|
|
216
|
+
numbered_printer(['a', 'b', 'c']) # Prints: 1. a\n2. b\n3. c
|
|
217
|
+
result = bullet_printer(['x', 'y', 'z']) # Returns: '• x\n• y\n• z'
|
|
218
|
+
compact_printer(['item1', 'item2']) # Prints: item1, item2
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Convenience Methods
|
|
222
|
+
|
|
223
|
+
The `print_list` object provides convenient pre-configured methods:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
# Quick access to common styles
|
|
227
|
+
print_list.compact(items) # Compact format, no count
|
|
228
|
+
print_list.wrapped(items) # Wrapped format, no count
|
|
229
|
+
print_list.columns(items) # Column format, no count
|
|
230
|
+
print_list.numbered(items) # Numbered format, no count
|
|
231
|
+
print_list.bullets(items) # Bullet format, no count
|
|
232
|
+
|
|
233
|
+
# Specialized methods
|
|
234
|
+
print_list.as_table(data) # Table with headers
|
|
235
|
+
print_list.summary(items) # Summary for long lists
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Advanced Examples
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
# Table with custom data
|
|
242
|
+
data = [['Name', 'Age', 'City'], ['Alice', 25, 'NYC'], ['Bob', 30, 'LA']]
|
|
243
|
+
print_list.as_table(data)
|
|
244
|
+
|
|
245
|
+
# Summary for long lists
|
|
246
|
+
long_list = list(range(100))
|
|
247
|
+
print_list.summary(long_list, max_items=6) # Shows: [0, 1, 2, ..., 97, 98, 99]
|
|
248
|
+
|
|
249
|
+
# Custom print function (e.g., for logging)
|
|
250
|
+
def my_logger(msg):
|
|
251
|
+
print(f"[LOG] {msg}")
|
|
252
|
+
|
|
253
|
+
print_list(items, style='bullet', print_func=my_logger)
|
|
254
|
+
|
|
255
|
+
# Combine partial with custom parameters
|
|
256
|
+
custom_compact = print_list(style='compact', sep=' | ')
|
|
257
|
+
custom_compact(items) # Prints: apple | banana | cherry | date | elderberry | fig
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Key Features
|
|
261
|
+
|
|
262
|
+
- **Multiple Styles**: `wrapped`, `columns`, `numbered`, `bullet`, `compact`, `table`
|
|
263
|
+
- **Flexible Output**: Print directly or return strings with `print_func=None`
|
|
264
|
+
- **Partial Functions**: Create reusable printers with pre-configured settings
|
|
265
|
+
- **Customizable**: Control width, separators, line prefixes, and more
|
|
266
|
+
- **Type Safe**: Uses `Literal` types for style validation
|
|
267
|
+
- **Self-Contained**: No external dependencies beyond Python standard library
|
|
268
|
+
|
|
269
|
+
The `print_list` function is perfect for debugging, logging, user interfaces, and any situation where you need to display lists in a readable format.
|
|
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
|