Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100662

return from function

From Emil Natan <shlyoko@gmail.com>
Newsgroups comp.lang.python
Subject return from function
Date 2015-12-20 12:34 +0000
Message-ID <mailman.22.1450699272.2237.python-list@python.org> (permalink)

Show all headers | View raw


I'm completely new to Python.
I have the following function to find the parent for domain. It removes the
left most label from the name and then checks if SOA record exists for the
reminder, if not it calls itself recursively removing another label and
checking again for SOA record. It works well for 'co.uk' and 'amazon.co.uk'
for example. It does not return the expected value 'uk' when invoked for '
amazon1.co1.uk', though the print command before the return prints what is
expected. Can someone explain why? Thanks.

>>> find_parent_domain('amazon.co1.uk.')
Test for parent domain co1.uk.
NXDOMAIN: invoke find_parent_domain recursively
Test for parent domain uk.
the parent domain we use is: uk.
>>>

import dns.resolver
from dns.exception import DNSException

def find_parent_domain(domainname):

    if domainname == '.':
        parent_domain = None
        return parent_domain

    parent_domain = domainname.partition('.')[2]
    try:
        print('Test for parent domain %s' % parent_domain)
        z = dns.resolver.query(parent_domain, 'SOA')
        print('the parent domain we use is: %s' % parent_domain)
        return parent_domain
    except dns.resolver.NXDOMAIN:
        print('NXDOMAIN: invoke find_parent_domain recursively')
        find_parent_domain(parent_domain)
    except dns.resolver.NoAnswer:
        print('NoAnswer: invoke find_parent_domain recursively')
        find_parent_domain(parent_domain)

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

return from function Emil Natan <shlyoko@gmail.com> - 2015-12-20 12:34 +0000
  Re: return from function Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-12-21 12:07 +0000
  Re: return from function Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-22 14:23 +0000

csiph-web