I have txt be like this " 01100000,10101000,01101000,01110000,10101100,01110000,01101000 " how can I read this file to use it in this code ?
value = " how can read file here"
vdiv = [value[i:i 8] for i in range(0, len(value), 8)]
def diff(inp):
if inp == '1':
return (0,0,0)
if inp == '0':
return (255,255,255)
else:
pass
img = Image.new( 'RGB', (8,len(vdiv)), "white")
pixels = img.load()
##
for x in range(img.size[0]):
for y in range(img.size[1]):
for i in vdiv:
for i2 in i:
pixels[x,y] = diff(i2) #Creates a black image. What do?
img.show()
CodePudding user response:
You can use open('filename.txt', 'r').read()
like so:
fd = open('filename.txt', 'r')
value = fd.read()
fd.close()
...