N
N
nbsp1122020-10-29 21:27:35
Python
nbsp112, 2020-10-29 21:27:35

Python does not save changes to the database when importing a function?

there is a file
a.py -> there is a function in it:

def myfunc( url, browser, db):
  """
  browser =  webdriver.Chrome as browser
  url - какую страницу открываем в браузере
  скрапим данные, обрабатываем и записываем в базу
  db - база sqlite3
  db.commit()
  всё работает прекрасно
  """
  pass


b.py -> in it we do:
from a import myfunc


db = sqlite3.connect('./db.db')
cur = db.cursor()

url = http://someurl.com

with webdriver.Chrome as browser:
  myfunc(url, browser, db)


and here we get a plug - the function does not save changes in the database
, we run the same thing from a.py - the database is updated
from b.py - the data is not saved

, what is the logic? how it works ? what needs to be done to make it work? :D

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krundetz, 2020-10-30
@krundetz

so you
only have a comment in your function, pass and nothing else
if you have it that way, then everything is logical that you wrote the function and executed
if not, then show the real code
, and you still have a context manager up to the function itself, it can generally not reach

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question