Skip to content

Commit 2c77ac8

Browse files
committed
v0.0.2 +table formatting
1 parent c3c6c90 commit 2c77ac8

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from setuptools import setup, find_packages
22
import codecs
33
import os
4+
from pathlib import Path
45

5-
VERSION = '0.0.1'
6+
7+
VERSION = '0.0.2'
68
DESCRIPTION = 'Utils for strings in python'
7-
LONG_DESCRIPTION = 'A package that provides useful functions for strings in python'
9+
this_directory = Path(__file__).parent
10+
LONG_DESCRIPTION = (this_directory / "README.md").read_text()
811

912
# Setting up
1013
setup(
@@ -22,8 +25,5 @@
2225
"Development Status :: 1 - Planning",
2326
"Intended Audience :: Developers",
2427
"Programming Language :: Python :: 3",
25-
"Operating System :: Unix",
26-
"Operating System :: MacOS :: MacOS X",
27-
"Operating System :: Microsoft :: Windows",
2828
]
29-
)
29+
)

string_py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = "string_py"
2-
__version__ = "0.0.1"
2+
__version__ = "0.0.2"
33
__license__ = "MIT"
44
__author__ = "BabyEntchen"
55
__copyright__ = "Copyright 2023 BabyEntchen"

string_py/string_py.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,41 @@ def align(values: dict[str, str]):
209209
for key in values:
210210
aligned_text += key + " " * ((length + 3) - len(key)) + values[key] + "\n"
211211
return aligned_text
212+
213+
214+
@staticmethod
215+
def table(values: list[list[str]], border: bool = True) -> str:
216+
"""Create a table
217+
218+
Parameters
219+
----------
220+
:param values:`list[list[str]]`
221+
The values you want to print
222+
:param border:`True`
223+
Set to `False` to remove the border
224+
:return:
225+
Returns the table as string
226+
"""
227+
228+
length = [max([len(str(x)) for x in column]) for column in zip(*values)]
229+
if border:
230+
table = "\u250C" + "\u2500" * (sum(length) + (3 * len(values) - 1)) + "\u2510\n"
231+
for index, row in enumerate(values):
232+
table += "\u2502"
233+
for i, column in enumerate(row):
234+
table += " " + column + " " * (length[i] - len(column)) + " \u2502"
235+
if index == 0:
236+
table += "\n\u251C" + "\u2500" * (sum(length) + (3 * len(values) - 1)) + "\u2524" + "\n"
237+
else:
238+
if index != len(values) - 1:
239+
table += "\n\u2502" + "\u2500" * (sum(length) + (3 * len(values) - 1)) + "\u2502" + "\n"
240+
else:
241+
table += "\n\u2514" + "\u2500" * (sum(length) + (3 * len(values) - 1)) + "\u2518"
242+
else:
243+
table = ""
244+
for index, row in enumerate(values):
245+
for i, column in enumerate(row):
246+
table += " " + column + " " * (length[i] - len(column)) + " "
247+
if index != len(values) - 1:
248+
table += "\n"
249+
return table

0 commit comments

Comments
 (0)