Answer the question
In order to leave comments, you need to log in
How to call a method inside a class?
Tell me how to do it right.
I need to call the get_connection method inside another get_address method.
After that, outside the class, I need to call the get_address method
class DataBase():
def get_connection(self):
global __connection
if __connection is None:
__connection = sqlite3.connect('univer_info.db')
return __connection
def get_address(keyword: str):
conn = get_connection()
c = conn.cursor()
c.execute('SELECT nameAddress FROM address WHERE keyWord=?', (keyword,))
(res,) = c.fetchone()
return res
print(DataBase.get_address('2'))
Answer the question
In order to leave comments, you need to log in
self.get_address('2')
?
Calling a class method in another method of the same class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question