Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit fdac02b

Browse files
author
PokestarFan
committed
New changes
1 parent 8645f18 commit fdac02b

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,11 @@ ENV/
101101
.mypy_cache/
102102

103103
#sphinx
104-
docs\
104+
docs\
105+
.pypirc
106+
Makefile
107+
make.bat
108+
source*
109+
110+
#my custom file
111+
setupcommands.bat

markdowntable/__init__.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from __future__ import print_function, unicode_literals
2+
3+
4+
class Table():
5+
"""docstring for Table.
6+
This is the main class. It adds rows and columns, with data
7+
"""
8+
def __init__(self, name):
9+
super(Table, self).__init__()
10+
self.rows = 0
11+
self.columns = 1
12+
self.table = '''|{}|'''.format(str(name))
13+
self.finalized = False
14+
15+
def debug(self):
16+
print('''Printing debug information:
17+
Rows: {rows}
18+
Columns: {cols}
19+
Finalized?: {fin}
20+
Table Content: {table}'''.format(rows = str(self.rows),
21+
cols = str(self.columns),
22+
fin = str(self.finalized),
23+
table = self.table))
24+
25+
def add_column(self, name):
26+
self.columns += 1
27+
self.table += '''{}|'''.format(name)
28+
29+
def all_columns(self, *args):
30+
for value in args:
31+
self.add_column(str(value))
32+
33+
def finalize_cols(self):
34+
finalizer = '\n|'
35+
for i in range(self.columns):
36+
finalizer += '---|'
37+
self.table += finalizer
38+
39+
def add_row(self,show_warning_message = True, *args):
40+
if not self.finalized:
41+
self.finalize_cols()
42+
self.finalized = True
43+
self.rows += 1
44+
row = '|'
45+
rows_made = 0
46+
for i in range(int(len(args))):
47+
row += '{}|'.format(str(args[i]))
48+
rows_made += 1
49+
if self.columns > rows_made:
50+
if show_warning_message:
51+
print('You did not enter in enough values. You entered in {} values out of {} values. The values that you did not enter in will be filled in with a blank space. You can stop this message from appearing by adding the argument show_warning_message = False'.format(str(rows_made), str(self.columns)))
52+
for i in range(int(self.columns-rows_made)):
53+
row += ' |'
54+
elif self.columns < rows_made:
55+
raise AssertionError('You entered in too many row values. Please only enter {} row names.'.format(str(self.columns)))
56+
self.table += '\n{}'.format(row)
57+
58+
def get_table(self):
59+
return self.table
60+
61+
62+
def export_table_to_file(self, filename = 'markdowntable', extension='txt', mode = 'w+', overwrite_warning = True):
63+
with open('{fname}.{ext}'.format(fname = str(filename), ext = str(extension)),str(mode)) as file:
64+
try:
65+
contents = file.read()
66+
if mode == 'w' or mode == 'w+':
67+
mode_check = True
68+
if len(contents) > 0 and overwrite_warning and mode_check:
69+
print('This file already contains content. Do you want to overwrite the contents of the file? You can add the argument mode = a[+] to not overwrite.')
70+
except(io.UnsupportedOperation):
71+
pass
72+
file.write(table)
73+
return True

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
setup(name='markdowntable',
5-
version='2.0',
5+
version='4.0.1.2',
66
description='Easy way to make markdown code for tables',
77
url='https://github.com/PokestarFan/Python-Markdown-Table',
88
author='PokestarFan',

0 commit comments

Comments
 (0)