I have a 10x10 np array which consists of dots and characters. The characters move in a random pattern, after every move i print the array to the consol, but it looks laggy and weird, i wanted to ask if you guys know a way how i can make this look prettier? Im only allowed to use standard python libraries.
class World:
def __init__(self, x, y):
self.x = x
self.y = y
self.world = np.empty((self.x, self.y), dtype=object)
self.world.fill(None)
Here i created the array, which is filled with symbols or nothing
def print_world(self):
for i in range(self.x):
for j in range(self.y):
if self.world[i, j] == None:
print('.', end=' ')
else:
print(self.world[i, j].symb, end=' ')
print()
this is the actual print, and my question is how i can make this look prettier, regarding its lagginess not its visuals. Thank you
As suggested by JonSG avoid calling multiple print
should improve lag.
def print_world(self):
world_str = str()
for x in range(self.x):
for y in range(self.y):
if self.world[x, y] is None:
world_str += ". "
else:
world_str += self.world[x, y].symb
world_str += "\n"
print(world_str)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.