I need to read a list of colors from txt file. For example color.txt which looks like this:
red
blue
green
what I do is:
with open('color.txt') as f:
line = f.readline().strip()
when calling 'line' my result comes as:
'red'
'blue'
'green'
However, I need my output without ' ' as:
red
blue
green
Is the problem in encoding of my txt file? Or am I doing something wrong? Thanks in advance for help.
UPDATE: Since there is no clear understanding on what I do here, please see the full code. The program shall print colorful rectangles in defined number of columns. The amount of rectangles is defined by amount of colors in the file. Each rectangle has color as per line, one by one.
import tkinter
canvas = tkinter.Canvas()
canvas.pack()
def stvor(file, width):
a = 30
pocetr = 0
z = 0
with open(file, 'r') as f:
x = 10
y = 10
for line in f: #line counter
pocetr += 1
for b in range(pocetr): #defined how many rectangles shall be drawn
z += 1
col = f.readline().strip() #reading color from a file
canvas.create_rectangle(x, y, x+a, y+a, fill = col)
x = x + a
if z == width: #if the width reaches certain level continue in new line
y = y + a
x = 10
z = 0