Ultimate GPS example python code not working

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
razr
 
Posts: 5
Joined: Wed Oct 15, 2014 3:14 pm

Ultimate GPS example python code not working

Post by razr »

Hello!

I just got my Ultimate GPS up and running and have my WebIDE installed and running too.
I used the python code included in the pdf to the gps
https://learn.adafruit.com/downloads/pd ... rry-pi.pdf

But when I run it though WebIDE I get the message:

Code: Select all

sudo python pigps.py
  File "pigps.py", line 12
    print report
        ^
SyntaxError: invalid syntax
¨

This is what my code looks like:

Code: Select all

import gps

#Listen to port 2947 (gpsd) of localhost
session = gps.gps("localhost","2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
    try:
        report = session.next()
    # Wait for a 'TPV' report and display the current time
    # To see all data, uncomment the line below
    print report
        if report['class'] == 'TPV':
            if hasattr(report,'time'):
                print report.time
    except KeyError:
pass
    except KeyboardInterrupt:
quit()
    except StopIteratoin:
session = None
print "GPSD har terminated"

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS example python code not working

Post by adafruit_support_rick »

Your indentation is not correct. "print report" should be indented by another tab stop.

razr
 
Posts: 5
Joined: Wed Oct 15, 2014 3:14 pm

Re: Ultimate GPS example python code not working

Post by razr »

Okay!

But now I got the same error on line 17
Indentation error at "pass"

Tried to put a tab there but I think I'm missing somethign

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Ultimate GPS example python code not working

Post by adafruit_support_rick »

You need two tabs after an except. So you need two leading tabs on pass, quit(), session = None, and print "GPSD har terminated"

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”