i’m making a game where the level loads in via a txt file but a can’t take the lines out of the file so my program can read it
this is the ecstraction code
def create_level():
global Level
Level = []
file = open(“level_file.txt”,”r”)
lines_in_file = file.readlines()
#Level = lines_in_file
number_of_lines = len(lines_in_file)
#print(number_of_lines)
for line in range(number_of_lines):
to_write = lines_in_file[line]
Level = Level + [“(” + to_write.rstrip(“n”) + “)”]
print(Level)
and the file looks like this
-30,-30,400,40
40,40,200,40
0,550,600,40
the output i want is:
[(-30,-30,200,40),(40,40,200,40),(0,550,600,40)]
but the output i get is:
[‘(-30,-30,200,40)’, ‘(40,40,200,40)’, ‘(0,550,600,40)’]
konrad Larsson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.