0
Python: how I could access to item values in list?
Hello all, I read TXT file trought a list. But how I could access to item values in the list? Thank you in advance for answers! Code: with open( dat, "r", encoding="ANSI" ) as f: lines=f.read().split() print( lines.__str__()) f.close() The result is: ['""', '""', '""', '""', '""', '""', '"Interval:', '01/01/17', '00:00:00', '-', '31/01/17', '23:59:59"', '""']
2 Respuestas
+ 1
If you want to access (lines) outside the with cycle, you need to declare the variable before the loop.
lines = []
with open(dat, "r", encoding="ANSI") as f:
lines = f.read().split()
print(lines.__str__())
f.close()
for elem in lines:
print(elem)
print(lines[0])
0
thanks a lot, Eugene!!!!!