B
B
Brutus12020-07-02 11:06:02
Python
Brutus1, 2020-07-02 11:06:02

How to call completion for from another function?

There is a grab() function that looks something like this:

def grab():
  """Сбор информации о хешах"""
  for link in links:
    url = link.get('href', '-')
    image_url = link.find('img').get('src', '-')
    print(url, image_url)
    #Скачаем картинку
    filename = 'temp.png'
    r = requests.get(image_url, headers=headers)
    if r.status_code == 200:
      print('ok')
      with open(filename, 'wb') as f:
        f.write(r.content)
    for mi in range(10):
      if True:
        compare(mi,image_url,url)
      else:
        break


and the compare(mi,image_url,url) function is built into it,
it looks like this:
def compare(mi,image_url,url):
  """Сравнивает картинки, принимает индекс mi"""
  if np.allclose(img, img2):
    print("Подходит!")
    global hashes
    hashes[mi] = image_url
  else:
    print("Дальше!")
    #time.sleep(0.2)


and so, the question is, if the message comes out Suitable!
you need to prematurely terminate the execution of which is inside grab () but how to pass it through compare ()? for mi in range(10)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-07-02
@Brutus1

Interesting design

if True:
        compare(mi,image_url,url)
else:
        break

def grab():
  """Сбор информации о хешах"""
  for link in links:
    url = link.get('href', '-')
    image_url = link.find('img').get('src', '-')
    print(url, image_url)
    #Скачаем картинку
    filename = 'temp.png'
    r = requests.get(image_url, headers=headers)
    if r.status_code == 200:
      print('ok')
      with open(filename, 'wb') as f:
        f.write(r.content)
    
    success = False
    for mi in range(10):
        success = compare(mi,image_url,url)
        if success:
            break

def compare(mi,image_url,url):
  """Сравнивает картинки, принимает индекс mi"""
  if np.allclose(img, img2):
    print("Подходит!")
    global hashes
    hashes[mi] = image_url
    return True
  else:
    print("Дальше!")
    #time.sleep(0.2)
    return False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question