#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    10
    Rep Power
    0

    Problem with print (Indentation?)


    I am on linux and have python 2.7 and 3.2 installed.

    When i run the below script I get this error.

    File "./1query.py", line 14
    print arec
    ^
    SyntaxError: invalid syntax

    I also received this error when attempting to run a second script.
    I played with the indentation and the error switched between "invalid syntax" and "unexpected indent"


    Code:
    #!/usr/bin/python3.2  
    
    import dns.resolver hosts = ["oreilly.com", "yahoo.com", google.com", "microsoft.com", "cnn.com"] 
    def query(host_list=hosts):   
      collection = []   
      for host in host_list:     
        ip = dns.resolver.query(host,"A")     
        for i in ip:       
          collection.append(str(i))   
       return collection 
      if __name__ == "__main__":   
         for arec in query():     
            print arec
    Thanks for reading
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,696
    Rep Power
    480
    print() is a function in python3.

    Thus
    print 'whoops'
    is a syntax error just as you'd expect
    len 'missing parentheses'
    to be a syntax error.

    You're missing a quote mark before google:
    import dns.resolver hosts = ["oreilly.com", "yahoo.com", google.com", "microsoft.com", "cnn.com"]
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo