Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try :
- from termcolor import colored
- except ImportError :
- import os
- os.system("pip install termcolor")
- from termcolor import colored
- class Grid:
- def __init__(self, x, y, debug=False):
- self.x = x
- self.y = y
- self.gridValue = self.x * self.y
- self.grid = {}
- self.debug = debug
- count = 1
- # initialising grid
- """
- for i in range(self.x) :
- self.grid[f"column{i}"] = None
- for x in range(self.y):
- for i in range(self.x) :
- print(i)
- if i == 0 :
- count += 1
- print(count - 1)
- self.grid[f"row{i}"] = {f"column{i}"}
- """
- for i in range(self.gridValue) :
- self.grid[f"obj{i}"] = None
- if self.debug == True :
- print(self.grid)
- print(self.gridValue)
- print(len(self.grid))
- self.gridIntermostPartsToComplete = self.gridValue - len(self.grid)
- print(colored("If this shows something other than 0, Something is wrong :", "blue"))
- print(colored(self.gridIntermostPartsToComplete, "green"))
- if self.gridIntermostPartsToComplete != 0 :
- print(colored("Thats an error! The intermost parts need building! Your parameters may be incorrect or your module might be faulty!", "red"))
- def insert(self, data, object):
- self.grid[object] = data
- def visualize(self):
- table = []
- for i in range(len(self.grid)) :
- if i % self.x == 0 :
- current = str(self.grid[f'obj{i}']) + "\n"
- print(current),
- table.append(current)
- else :
- current = str(self.grid[f'obj{i}'])
- print(current),
- table.append(current)
- if self.debug == True :
- print(table)
- '''
- for i in range(len(table)) :
- print(table[i], sep="")
- '''
- # column=x, row=y
- grid = Grid(4,4, debug=False)
- grid.insert("hi","obj2")
- grid.insert("hello", "obj1")
- grid.insert("hey", "obj0")
- grid.visualize()
Advertisement
Add Comment
Please, Sign In to add comment