hi i want to save the position of all the lines that contains "CREATE TABLE" in a list a) is there a better and right way to do it? (i'm new to python) b) why does it matter that tell is being used for the iterator? i thought it's a read method (or equivalent) thus just telling the position shouldn't hurt the file iteration proccess.
so i have the following class:
class SQLParser(object):
def __init__(self,filename):
self.file = open(filename,'r')
self.createTablePositions=[]
self.insertIntoPositions=[]
def findCreateTable(self):
for line in self.file:
if line.find("CREATE TABLE") is 0:
print(line)
self.createTablePositions.append(self.file.tell())
sqlhandler = SQLParser("sql.sql")
sqlhandler.findCreateTable()
print(sqlhandler.createTablePositions)
that yields the following error: "Traceback (most recent call last): File "C:/Users/user/PycharmProjects/sqlparser/sqlparser.py", line 18, in sqlhandler.findCreateTable() File "C:/Users/user/PycharmProjects/sqlparser/sqlparser.py", line 12, in findCreateTable curPos = self.file.tell() OSError: telling position disabled by next() call"
i've searched the net and stackoverflow but i didn't find a direct solution to my problem. --currently solution like rewritting next() method are beyond my knowledge and i doubt this excercise aims for that.
please your advice will be highly appriciated!