Reference to value of the function
Question: At beginning i wanna say i'm newbie in use Python and everything I learned it
came from tutorials. My problem concerning reference to the value. I'm writing
some script which is scrapping some information from web sites. I defined some
function:

    
    
    def MatchPattern(count):
        sock = urllib.urlopen(Link+str(count))
        htmlSource = sock.read()                             
        sock.close()
        root = etree.HTML(htmlSource)
        root = etree.HTML(htmlSource)
        result = etree.tostring(root, pretty_print=True, method="html")
        expr1 = check_reg(root)
        expr2 = check_practice(root)
        D_expr1 = no_ks(root)
        D_expr2 = Registred_by(root)
        D_expr3 = Name_doctor(root)
        D_expr4 = Registration_no(root) 
        D_expr5 = PWZL(root)
        D_expr6 = NIP(root)
        D_expr7 = Spec(root)
        D_expr8 = Start_date(root)
    
        #-----Reg_practice-----
        R_expr1 = Name_of_practise(root) 
        R_expr2 = TERYT(root) 
        R_expr3 = Street(root)
        R_expr4 = House_no(root)
        R_expr5 = Flat_no(root)
        R_expr6 = Post_code(root)
        R_expr7 = City(root)
        R_expr8 = Practice_no(root)
        R_expr9 = Kind_of_practice(root)
    
        #------Serv_practice -----
        S_expr1 = TERYT2(root)
        S_expr2 = Street2(root)
        S_expr3 = House_no2(root)
        S_expr4 = Flat_no2(root)
        S_expr5 = Post_code2(root)
        S_expr6 = City2(root)
        S_expr7 = Phone_no(root)
    
        return expr1
        return expr2
        return D_expr1
        return D_expr2
        return D_expr3
        return D_expr4 
        return D_expr5
        return D_expr6
        return D_expr7
        return D_expr8
    
        #-----Reg_practice-----
        return R_expr1 
        return R_expr2
        return R_expr3
        return R_expr4
        return R_expr5
        return R_expr6
        return R_expr7
        return R_expr8
        return R_expr9
    
        #------Serv_practice -----
        return S_expr1
        return S_expr2
        return S_expr3
        return S_expr4
        return S_expr5
        return S_expr6
        return S_expr7
    

So now inside the script I wanna check value of the expr1 returned by my
fynction. I don't know how to do that. Can u guys help me ? Is my function
written correct ?

EDIT: I can't add answer so I edit my current post

This is my all script. Some comments are in my native language but i add some
in english

    
    
    #! /usr/bin/env python
    #encoding:UTF-8-
    
    # ----------------------------- importujemy potrzebne biblioteki i skrypty -----------------------
    # ------------------------------------------------------------------------------------------------
    import urllib
    from lxml import etree, html
    import sys
    import re
    import MySQLdb as mdb
    from TOR_connections import *
    from XPathSelection import *
    import os
    
    # ------------------------------ Definiuje xPathSelectors ------------------------------------------
    # --------------------------------------------------------------------------------------------------
    # -------Doctors -----
    check_reg = etree.XPath("string(//html/body/div/table[1]/tr[3]/td[2]/text())") #warunek Lekarz
    check_practice = etree.XPath("string(//html/body/div/table[3]/tr[4]/td[2]/text())") #warunek praktyka
    
    no_ks = etree.XPath("string(//html/body/div/table[1]/tr[1]/td[2]/text())")
    Registred_by = etree.XPath("string(//html/body/div/table[1]/tr[4]/td[2]/text())")
    Name_doctor = etree.XPath("string(//html/body/div/table[2]/tr[2]/td[2]/text())")
    Registration_no = etree.XPath("string(//html/body/div/table[2]/tr[3]/td[2]/text())") 
    PWZL = etree.XPath("string(//html/body/div/table[2]/tr[4]/td[2]/text())") 
    NIP = etree.XPath("string(//html/body/div/table[2]/tr[5]/td[2]/text())") 
    Spec = etree.XPath("string(//html/body/div/table[2]/tr[18]/td[2]/text())") 
    Start_date = etree.XPath("string(//html/body/div/table[2]/tr[20]/td[2]/text())") 
    
    #-----Reg_practice-----
    Name_of_practise = etree.XPath("string(//html/body/div/table[2]/tr[1]/td[2]/text())") 
    TERYT = etree.XPath("string(//html/body/div/table[2]/tr[7]/td[2]/*/text())") 
    Street = etree.XPath("string(//html/body/div/table[2]/tr[8]/td[2]/text())") 
    House_no = etree.XPath("string(//html/body/div/table[2]/tr[9]/td[2]/*/text())")
    Flat_no = etree.XPath("string(//html/body/div/table[2]/tr[10]/td[2]/*/text())")
    Post_code = etree.XPath("string(//html/body/div/table[2]/tr[11]/td[2]/*/text())")
    City = etree.XPath("string(//html/body/div/table[2]/tr[12]/td[2]/*/text())") 
    Practice_no = etree.XPath("string(//html/body/div/table[3]/tr[4]/td[2]/text())")
    Kind_of_practice = etree.XPath("string(//html/body/div/table[3]/tr[5]/td[2]/text())")
    
    #------Serv_practice -----
    TERYT2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[2]/td[2]/*/text())") 
    Street2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[3]/td[2]/text())") 
    House_no2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[4]/td[2]/*/text())") 
    Flat_no2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[5]/td[2]/i/text())") 
    Post_code2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[6]/td[2]/*/text())") 
    City2 = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[7]/td[2]/*/text())")
    Phone_no = etree.XPath("string(//html/body/div/table[3]/tr[14]/td/table/tr[8]/td[2]/text())")
    
    # --------------------------- deklaracje zmiennych globalnych ----------------------------------
    # ----------------------------------------------------------------------------------------------
    decrease = 9
    No = 1
    Link = "http://rpwdl.csioz.gov.pl/rpz/druk/wyswietlKsiegaServletPub?idKsiega="
    
    # --------------------------- funkcje zdefiniowane ----------------------------------
    # ----------------------------------------------------------------------------------------------
    def MatchPattern(count):
        sock = urllib.urlopen(Link+str(count))
        htmlSource = sock.read()                             
        sock.close()
        root = etree.HTML(htmlSource)
        root = etree.HTML(htmlSource)
        result = etree.tostring(root, pretty_print=True, method="html")
        expr1 = check_reg(root)
        expr2 = check_practice(root)
        D_expr1 = no_ks(root)
        D_expr2 = Registred_by(root)
        D_expr3 = Name_doctor(root)
        D_expr4 = Registration_no(root) 
        D_expr5 = PWZL(root)
        D_expr6 = NIP(root)
        D_expr7 = Spec(root)
        D_expr8 = Start_date(root)
    
        #-----Reg_practice-----
        R_expr1 = Name_of_practise(root) 
        R_expr2 = TERYT(root) 
        R_expr3 = Street(root)
        R_expr4 = House_no(root)
        R_expr5 = Flat_no(root)
        R_expr6 = Post_code(root)
        R_expr7 = City(root)
        R_expr8 = Practice_no(root)
        R_expr9 = Kind_of_practice(root)
    
        #------Serv_practice -----
        S_expr1 = TERYT2(root)
        S_expr2 = Street2(root)
        S_expr3 = House_no2(root)
        S_expr4 = Flat_no2(root)
        S_expr5 = Post_code2(root)
        S_expr6 = City2(root)
        S_expr7 = Phone_no(root)
    
        return expr1
        return expr2
        return D_expr1
        return D_expr2
        return D_expr3
        return D_expr4 
        return D_expr5
        return D_expr6
        return D_expr7
        return D_expr8
    
        #-----Reg_practice-----
        return R_expr1 
        return R_expr2
        return R_expr3
        return R_expr4
        return R_expr5
        return R_expr6
        return R_expr7
        return R_expr8
        return R_expr9
    
        #------Serv_practice -----
        return S_expr1
        return S_expr2
        return S_expr3
        return S_expr4
        return S_expr5
        return S_expr6
        return S_expr7
    
    
    
    
    # --------------------------- ustanawiamy polaczenie z baza danych -----------------------------
    # ----------------------------------------------------------------------------------------------
    con = mdb.connect('localhost', 'root', '******', 'SANBROKER', charset='utf8');
    
    # ---------------------------- początek programu -----------------------------------------------
    # ----------------------------------------------------------------------------------------------
    
    with con: 
        cur = con.cursor()
        cur.execute("SELECT Old_num FROM SANBROKER.Number_of_records;")
        Old_num = cur.fetchone()
        count = Old_num[0]
        counter = input("Input number of rows: ")
    
        # ----------------------- pierwsze połączenie z TORem ------------------------------------
        # ----------------------------------------------------------------------------------------
        #connectTor()
        #conn = httplib.HTTPConnection("my-ip.heroku.com")
        #conn.request("GET", "/")
        #response = conn.getresponse()
        #print(response.read())
    
        while count <= counter: # co dziesiata liczba
            # --------------- pierwsze wpisanie do bazy danych do Archive --------------------
            with con:
                cur = con.cursor()
                cur.execute("UPDATE SANBROKER.Number_of_records  SET Archive_num=%s",(count))
    
            # ---------------------------------------------------------------------------------
            if decrease == 0:
                MatchPattern(count)
    
                # Now I wanna check some expresions (2 or 3)
                # After that i wanna write all the values into my database
    
    
                #------- ostatnie czynności:
                percentage = count / 100
                print "rekordów: " + str(count) + " z: " + str(counter) + " procent dodanych: " + str(percentage) + "%"  
                with con:
                    cur = con.cursor()
                    cur.execute("UPDATE SANBROKER.Number_of_records SET Old_num=%s",(count))
                decrease = 10-1
                count +=1
            else:
                MatchPattern(count)
    
                # Now I wanna check some expresions (2 or 3)
                # After that i wanna write all the values into my database
    
                # ------ ostatnie czynności:
                percentage = count / 100
                print "rekordów: " + str(count) + " z: " + str(counter) + " procent dodanych: " + str(percentage) + "%"
                with con:
                    cur = con.cursor()
                    cur.execute("UPDATE SANBROKER.Number_of_records SET Old_num=%s",(count))
                decrease -=1
                count +=1
    


Answer: Well, I'm assuming check_reg is a function that returns a boolean (either True
or False).

If that's the case, to check the return:

    
    
    if expr1:
       print "True."
    else: 
       print "False"
    

There's more than one way to do it, but basically, `if expr1:` is all you need
to do the checking.

