0

This is my Python code. If the line has : I'm want to skip this line and the next line. I'm trying to use file.next since file is an iterator. Why is it not working?

file=open("example.txt","r") //output of ls -R

currentDirectory=""
for line in file:
    if ":" in line:
        currentDirectory=line[:-1]
        file.next() # Error in this line
        continue
    A=line.split()
    print(A)
    print(len(A))
    print('insert into files set name=${name}, inode=${inode}, isDir=${isDir},size=${size}'
    .format(inode=A[0],name=A[9],isDir="d" in A[1],size=A[5]))

The error:

Traceback (most recent call last):
  File "ls-to-sql.py", line 7, in <module>
    file.next()
AttributeError: '_io.TextIOWrapper' object has no attribute 'next

I'm sure there are many other ways to implement the same logic. The question is: why this is not working. And if there is another iteration way to solve it.

Anmol Singh Jaggi
  • 8,376
  • 4
  • 36
  • 77
Aminadav Glickshtein
  • 23,232
  • 12
  • 77
  • 117

0 Answers0