0

I'm trying to create a continuous question loop to process all my calculations for my nmea sentences in my project. For some reason only the first if statement is executed. What am I doing wrong? I'm still fairly new to python

   if command_type == "$GPGGA" or "GPGGA" or "GGA":
        #define the classes
        gps = GPS()
        createworkbook = CreateWorkbook()
        convertfile = ConvertFile()
        print_gps = PrintGPS()
        #do the deeds
        createworkbook.openworkbook(data)
        print_gps.process_gpgga_data(data)
        createworkbook.closeworkbook_gpgga(data) 
        convertfile.convert2csv(data)
        convertfile.convert2kml(data)
    if command_type == "$GPRMC" or "GPRMC" or "RMC":
        #define the classes
        gps = GPS()
        createworkbook = CreateWorkbook()
        convertfile = ConvertFile()
        print_gps = PrintGPS()
        #do the deeds
        createworkbook.openworkbook(data)
        print_gps.process_gprmc_data(data)
        createworkbook.closeworkbook_gprmc(data) 
        convertfile.convert2csv(data)
        convertfile.convert2kml(data)
    if command_type == "$GPGLL" or "GPGLL" or "GLL":
        #define the classes
        gps = GPS()
        createworkbook = CreateWorkbook()
        convertfile = ConvertFile()
        print_gps = PrintGPS()
        #do the deeds
        createworkbook.openworkbook(data)
        print_gps.process_gpgll_data(data)
        createworkbook.closeworkbook_gpgll(data) 
        convertfile.convert2csv(data)
        convertfile.convert2kml(data)
    if command_type == "$GPGSA" or "GPGSA" or "GSA":
        #define the classes
        gps = GPS()
        createworkbook = CreateWorkbook()
        convertfile = ConvertFile()
        print_gps = PrintGPS()
        #do the deeds
        createworkbook.openworkbook(data)
        print_gps.process_gpgsa_data(data)
        createworkbook.closeworkbook_gpgsa(data) 
        convertfile.convert2csv(data)  
    if command_type == "$GPVTG" or "GPVTG" or "VTG":
        print('Better check $GPRMC')
    else:
        print("Invalid type:", command_type)

    list_gps_commands(data)     
    wannalook = input('Want to look at another message or no?')
    if not wannalook.startswith('y'):
        keep_asking = False
        print('********************')
        print('**mischief managed**')
        print('********************')
vaultah
  • 44,105
  • 12
  • 114
  • 143
Daniel
  • 77
  • 3
  • 20

2 Answers2

2

Instead of:

 if command_type == "$GPGGA" or "GPGGA" or "GGA":

use:

  if command_type == "$GPGGA" or command_type == "GPGGA" or command_type == "GGA":

or:

if command_type in ["$GPGGA", "GPGGA", "GGA"]:
dot.Py
  • 5,007
  • 5
  • 31
  • 52
2
if command_type == "$GPGGA" or "GPGGA" or "GGA":

As you can see, here you are not trying to check if command_type is valued "$GPGGA" or "GPGGA" or "GGA". But if command_type == "$GPGGA" is true or "GPGGA" is true or "GGA" is true.

And a non-empty string in python is always true : your first condition will be evaluated true.

So you have to do :

if command_type == "$GPGGA" or command_type == "GPGGA" or command_type == "GGA"
Anthony Granger
  • 784
  • 9
  • 23