File tree Expand file tree Collapse file tree 3 files changed +45
-7
lines changed
Expand file tree Collapse file tree 3 files changed +45
-7
lines changed Original file line number Diff line number Diff line change 11from setuptools import setup , find_packages
22import codecs
33import os
4+ from pathlib import Path
45
5- VERSION = '0.0.1'
6+
7+ VERSION = '0.0.2'
68DESCRIPTION = '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
1013setup (
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+ )
Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments