Simple list question - I think? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Simple list question - I think? (/thread-10789.html) |
Simple list question - I think? - jhartacs - Jun-06-2018 Hello, This may be a simple question regarding lists. I am using dnspython to perform a dns.resolver to get all the records for a domain. It creates a list with an append and if I print that list, it gives me output like this [<DNS IN A rdata: 172.217.6.206>, <DNS IN AAAA rdata: 2607:f8b0:4006:812::200e>, Ultimately I am looking to strip and format this output to say "A 172.217.6.206" on one line and "AAAA 2607:f8b0:4006:812::200e" on another. I thought I could iterate through the list and print each line. When I do with the following code, it prints the answer and not the type of record like this. There is no <> symbols or information what type of record is on each line. What am I doing wrong? 172.217.10.110 2607:f8b0:4006:805::200e 50 alt4.aspmx.l.google.com. 20 alt1.aspmx.l.google.com. 10 aspmx.l.google.com. 30 alt2.aspmx.l.google.com. 40 alt3.aspmx.l.google.com. "v=spf1 include:_spf.google.com ~all" "facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95" "docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e" ns1.google.com. dns-admin.google.com. 199450551 900 900 1800 60 ns1.google.com. ns4.google.com. ns3.google.com. ns2.google.com. Here is my code. Currently it prints both of the examples import dns.resolver def dnstest(domain): dnsrecords = [] record_types = ['A', 'AAAA', 'CNAME', 'MX', 'SRV', 'TXT', 'SOA', 'NS'] dnsResolver = dns.resolver.Resolver() dnsResolver.timeout = 1 dnsResolver.lifetime = 1 for record in record_types: try: dnsAnswer = dnsResolver.query(domain, record) for rdata in dnsAnswer: dnsrecords.append(rdata) except: pass return(dnsrecords) mylist=(dnstest("acsgj.com")) # Print the list - creates the odd data print(mylist) # print each element - doesn't show the odd data or the type of record for i in mylist: print(i) RE: Simple list question - I think? - jhartacs - Jun-06-2018 As a follow up. I changed my print to a pprint and it shows all the information. |