My Python code:
mapArray = [["#","#","#"],["#","#","#"],["#","#","#"]]
for row in mapArray:
for cell in row:
print cell,
print
print
prints this:
# # #
# # #
# # #
why not this:
###
###
###
Thanks much!
My Python code:
mapArray = [["#","#","#"],["#","#","#"],["#","#","#"]]
for row in mapArray:
for cell in row:
print cell,
print
print
prints this:
# # #
# # #
# # #
why not this:
###
###
###
Thanks much!
My preferred solution when I want Python to only print what I tell it to without inserting newlines or spaces is to use sys.stdout:
from sys import stdout
mapArray = [["#","#","#"],["#","#","#"],["#","#","#"]]
for row in mapArray:
for cell in row:
stdout.write(cell)
stdout.write("\n")
stdout.write("\n")
The print statement documentation states, "A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line." This is why sys.stdout is the preferred solution here and is the reason why you're seeing spaces in your output.
Change your print cell, to sys.stdout.write(cell). After importing sys, of course.
write method of file-like objects takes strings. You may want sys.stdout.write(str(cell)), depending on what cell is.print function if you want it: from __future__ import print_function; print("a", "b", sep="", end=""); print("c")