PrettyTableX 0.1.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.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: PrettyTableX
3
+ Version: 0.1.0
4
+ Summary: A module that will help you make tables look pretty.
5
+ Author: SG-1022
6
+ Requires-Python: >=3.8
@@ -0,0 +1 @@
1
+ from .core import PrettyTable
@@ -0,0 +1,161 @@
1
+ class PrettyTable:
2
+
3
+ class TooLongError(Exception):
4
+ def __init__(self, msg="A row was to long."):
5
+ super().__init__(msg)
6
+
7
+ class TooShortError(Exception):
8
+ def __init__(self, msg="A row was to short."):
9
+ super().__init__(msg)
10
+
11
+ class NotEnoughIndexes(Exception):
12
+ def __init__(self, msg="There aren't enough indexes for each row."):
13
+ super().__init__(msg)
14
+
15
+ class NotAnArrayError(Exception):
16
+ def __init__(self, msg="This isn't a array."):
17
+ super().__init__(msg)
18
+
19
+ def __init__(self, ar, header="", row_index:bool = True, row_indexes:list = None, column_indexes:list=None):
20
+ self.ar = ar
21
+ self.header = header
22
+ self.pretty_table = False
23
+ self.row_index = row_index
24
+ self.column_indexes = column_indexes
25
+
26
+
27
+ if column_indexes is None:
28
+ self.column_index = False
29
+ else:
30
+ self.column_index = True
31
+
32
+ if row_indexes is None:
33
+ self.row_indexes = [i + 1 for i in range(len(ar))]
34
+ else:
35
+ self.row_indexes = row_indexes
36
+
37
+ def __str__(self):
38
+ if self.pretty_table:
39
+ return self.pretty_table
40
+ else:
41
+ a = ""
42
+ for i in self.ar:
43
+ a += str(i) + "\n"
44
+
45
+ return a
46
+
47
+
48
+ def check(self):
49
+ num1 = len(self.ar[0])
50
+ for i in self.ar:
51
+ try:
52
+ num1 != len(i)
53
+ except TypeError:
54
+ raise self.NotAnArrayError(f"You have to turn the {type(self.ar)} into a array using our predefined functions.")
55
+ if num1 != len(i):
56
+ if len(i) > num1:
57
+ raise self.TooLongError(f"Row {self.ar.index(i) + 1} is to long.")
58
+ elif len(i) < num1:
59
+ raise self.TooShortError(f"Row {self.ar.index(i) + 1} is to short.")
60
+ else:
61
+ raise Exception("Something happened...")
62
+
63
+
64
+ def make_table_pretty(self):
65
+ """This function turns your array into a better looking table.
66
+ THE ARRAY MUST BE A LIST. IF IT ISN'T, USE dict_to_array or tup_to_array to fix it."""
67
+ num1 = len(self.ar[0])
68
+ num2 = 0
69
+ res = []
70
+
71
+ self.check()
72
+
73
+
74
+
75
+ for i in self.ar:
76
+ for n in i:
77
+ if len(str(n) + "\t" + str(num1)) > num2:
78
+ num2 = len(str(n) + "\t" + str(num1))
79
+
80
+ if self.column_index:
81
+ for n in self.column_indexes:
82
+ if len(str(n) + "\t" + str(num1)) > num2:
83
+ num2 = len(str(n) + "\t" + str(num1))
84
+
85
+ if self.row_index:
86
+ lila = -1
87
+ for i in self.row_indexes:
88
+ if len(str(i)) > lila:
89
+ lila = len(str(i)) + 2
90
+ res.append("+")
91
+ res.append("-" * (lila))
92
+ for i in range(num1):
93
+ res.append("+")
94
+ res.append("-" * num2)
95
+ res.append("+")
96
+
97
+
98
+ res = "".join(res)
99
+
100
+
101
+
102
+
103
+ if self.header:
104
+ self.pretty_table = (
105
+ self.header.center(len(res)).replace(
106
+ self.header,
107
+ f"\033[1;4m{self.header}\033[0m"
108
+ ) + "\n"
109
+ )
110
+ else:
111
+ self.pretty_table = ""
112
+
113
+ if self.column_index:
114
+ a = self.column_indexes[:]
115
+
116
+ self.pretty_table += res + "\n"
117
+
118
+ if self.row_index:
119
+ self.pretty_table += "|" + " "*lila
120
+ for i in range(num1):
121
+ try:
122
+ self.pretty_table += "|" + str(self.column_indexes[0].center(num2))
123
+ del self.column_indexes[0]
124
+ except IndexError:
125
+ raise self.NotEnoughIndexes("There aren't as many indexes as columns.")
126
+
127
+
128
+ self.column_indexes = a[:]
129
+ del a
130
+
131
+ self.pretty_table += "|\n"
132
+
133
+ for i in self.ar:
134
+ self.pretty_table += str(res) + "\n"
135
+ if self.row_index:
136
+ a = self.row_indexes[:]
137
+ self.pretty_table += "|"
138
+ try:
139
+ self.pretty_table += str(self.row_indexes[0]).center(lila)
140
+ except IndexError:
141
+ raise self.NotEnoughIndexes("There aren't as many indexes as rows.")
142
+ del self.row_indexes[0]
143
+ for r in i:
144
+ self.pretty_table += "|" + str(r).center(num2)
145
+ self.pretty_table += "|\n"
146
+
147
+ if self.row_index:
148
+ self.row_indexes = a[:]
149
+
150
+
151
+ self.pretty_table += res
152
+
153
+ def dict_to_array(self):
154
+ """If your array is a dictionary. This will turn it into the array you need."""
155
+
156
+ self.ar = list(self.ar.values())
157
+
158
+ def tup_to_array(self):
159
+ """If your array is a tuple. This will turn it into the array you need."""
160
+
161
+ self.ar = [list(i) for i in self.ar]
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: PrettyTableX
3
+ Version: 0.1.0
4
+ Summary: A module that will help you make tables look pretty.
5
+ Author: SG-1022
6
+ Requires-Python: >=3.8
@@ -0,0 +1,7 @@
1
+ pyproject.toml
2
+ PrettyTable/__init__.py
3
+ PrettyTable/core.py
4
+ PrettyTableX.egg-info/PKG-INFO
5
+ PrettyTableX.egg-info/SOURCES.txt
6
+ PrettyTableX.egg-info/dependency_links.txt
7
+ PrettyTableX.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ PrettyTable
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "PrettyTableX"
7
+ version = "0.1.0"
8
+ description = "A module that will help you make tables look pretty."
9
+ requires-python = ">=3.8"
10
+
11
+ authors = [
12
+ { name = "SG-1022" }
13
+ ]
14
+
15
+ dependencies = []
16
+
17
+ [tool.setuptools]
18
+ packages = ["PrettyTable"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+