가능한 중복 :
Overriding the newline generation behaviour of Python's print statement
PPM image to ASCII art in Python파이썬 목록 질문
이 내 코드, 난 문자가 인쇄 있지만 나는 그들이 같은 줄에과에서 휴식 필요 라인의 끝.
import sys
def main(filename):
image = open(filename)
#reads through the first three lines
color = image.readline().splitlines()
size_width, size_height = image.readline().split()
max_color = image.readline().splitlines()
#reads the body of the file
pixels = image.read().split()
red = 0
green = 0
blue = 0
r_g_b_value = []
#pulls out the values of each tuple and coverts it to its grayscale value
for i in pixels:
if i != "\n" or " ":
if len(i) == 3:
red = int(i[0]) * .3
green = int(i[1]) * .59
blue = int(i[2]) * .11
elif len(i) == 2:
red == int(i[0])
green == int(i[1])
blue == 0
elif len(i) == 1:
red == int(i[0])
green == 0
blue == 0
r_g_b_value = [red + green + blue]
grayscale = []
character = []
for j in r_g_b_value:
if int(j) <= .2:
character = "M"
elif int(j) > .2 and int(j) <= .4:
character = "#"
elif int(j) > .4 and int(j) <= .6:
character = "A"
elif int(j) > .6 and int(j) <= .8:
character = "@"
elif int(j) > .8 and int(j) <= 1:
character = "$"
elif int(j) > 1 and int(j) <= 1.2:
character = "0"
elif int(j) > 1.2 and int(j) <= 1.4:
character = "e"
elif int(j) > 1.4 and int(j) <= 1.6:
character = "a"
elif int(j) > 1.8 and int(j) <= 2:
character = "o"
elif int(j) > 2 and int(j) <= 2.2:
character = "="
elif int(j) > 2.25 and int(j) <= 2.5:
character = "+"
elif int(j) > 2.5 and int(j) <= 2.75:
character = ";"
elif int(j) > 2.75 and int(j) <= 3:
character = ":"
elif int(j) > 3 and int(j) <= 3.4:
character = ","
elif int(j) > 3.4 and int(j) <= 3.9:
character = "."
else:
character = " "
character += character
grayscale = [character]
print(grayscale)
어떤 도움을 주시면 감사하겠습니다.
이 코드는 나를 깜짝 놀라게합니다! –
이전의 특정 질문이 실제로는 좋은 phooji라고 생각하지 마십시오. – Amber
@asmith : 귀하의 질문을 오래된 stackoverflow 질문의 중복으로 표시했습니다. 또한 본질적으로 매우 유사한 많은 질문을 던집니다. 이것은 권장하지 않습니다 (http://blog.stackoverflow.com/2009/04/a-day-in-the-penalty-box/). – phooji