0
class DBAction(object):
__conn = None
__cursor = None
__id = None
def __init__(self, arg):
self.__id = arg
self.__conn = sqlite3.connect('clientes.db')
self.__cursor = conn.cursor()
def insert(self):
sql = ''' INSERT INTO history(id,conversation)
VALUES(?,?) '''
self.__cursor.execute(sql, self.__id, "user : "+srt(self.__id))
self.__conn.commit()
def verify(self):
self.__cursor.execute("SELECT * FROM history WHERE id = '"+self.__id+"'")
rows = cur.fetchall()
for row in rows:
print(row)
The above class is returning the error:
self.__cursor.execute(sql, self.__id, "user : "+srt(self.__id))
NameError: name 'self' is not defined
And I don’t understand why, can anyone tell me why? I’m new to POO in python
eviye use names with prefix of two underscores
__
- this use is not for "private attributes" - any text you have said this is dated, and was written by an erroneous impression of the language in the past decade. In practice, it will only give you a headache.– jsbueno
I talk in more detail about this use of
__
in part: https://answall.com/questions/351309/sobrescrever-property-na-classe-filha/352209#352209– jsbueno