I'm doing some basic CSV files manipulation when I stumbled upon this problem, now I know how to avoid it but I just want to have a better understanding of what is going on.
Whenever I want to iterate the csv.reader
object, I can do so easily. However, whenever I try to turn the object into a list via another variable, it blocks the iterative loop that iterates the csv.reader
object from starting.
def checkPlayer(discordName, playerName):
with open ('PLAYERS.csv', 'r') as fil:
r = csv.reader(fil)
l = list(r)
lineNum = 1
for line in r:
print(line)
The l = list(r)
is what blocks the loop from executing.
The code below works fine, and the loop executes normally.
def checkPlayer(discordName, playerName):
with open ('PLAYERS.csv', 'r') as fil:
r = csv.reader(fil)
lineNum = 1
for line in r:
print(line)
I'm expecting the reason on why this happens is because when turning the csv.reader
to a list, an iteration of the object happens which means that it sets the csv.reader
object at the endpoint before executing the loop.