×

Discussion Board

Results 1 to 7 of 7

Thread: Reading lists

  1. #1
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    200

    Error reading lists

    I seek assistance with understanding how lists are accessed and their content stored. For this purpose I submit the following code snippet:

    Code:
            ...
            ...
            to_gps = conn.makefile("r", 0) 
            msg = to_gps.readline()  
            if msg.startswith("$GPGGA"):  
                    gps_data = msg.split(",")  
                    lat = gps_data[2]  
    		compassLat = gps_data[3]  
                    lon = gps_data[4]  
    		compassLon = gps_data[5]
    A sample readline looks like the following:

    Code:
    $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
    My attempt to access the 3rd & 5th elements of this list generates a SyntaxError. Would greatly appreciate assistance with its resolution.

    Best regards,
    wirefree101
    Last edited by wirefree101; 2009-06-05 at 09:07.

  2. #2
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    200

    Re: Error Reading lists

    Would greatly appreciate assistance with identifying the source of the error. The presumed source of error is in the last 3 lines of the aforementioned code, which are stated below for quick reference:

    Code:
    compassLat = gps_data[3]  
    lon = gps_data[4]  
    compassLon = gps_data[5]
    Best regards,
    wirefree101
    Last edited by wirefree101; 2009-06-05 at 09:08.

  3. #3
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Reading lists

    Could you please post the entire error exactly as you get it, with the little arrow and everything?

  4. #4
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    200

    Re: Error Reading lists

    Quote Originally Posted by bogdan.galiceanu View Post
    Could you please post the entire error exactly as you get it, with the little arrow and everything?
    As requested, I am providing the entire code below. Please refer to the while loop towards the end for the supposed source of error.


    Code:
    import appuifw, e32, key_codes, graphics, socket
    
    BLACK = (0,0,0)
    
    def draw_point():
        img.point((120,160), outline = YELLOW, width = 5)
    
    def handle_redraw(rect):
        if img: canvas.blit(img)
    
    def handle_event(event):
        ev = event['keycode']        
        
        if ev == key_codes.EKeyUpArrow:
            draw_point()
      
        handle_redraw(None)
    
    def quit():
        app_lock.signal()
    
    img = None
    canvas = appuifw.Canvas(redraw_callback = handle_redraw, event_callback = handle_event)
    appuifw.app.body = canvas
    appuifw.app.screen = 'full'
    appuifw.app.exit_key_handler = quit
    
    w, h = canvas.size
    img = graphics.Image.new((w, h))
    img = graphics.Image.open("E:\\Images\\canvas.jpg")
    canvas.blit(img)
    
    address, services = socket.bt_discover()  
    print "Discovered: %s, %s" % (address, services)  
    target = (address, services.values()[0])  
    conn = socket.socket(socket.AF_BT, socket.SOCK_STREAM)  
    conn.connect(target)  
    to_gps = conn.makefile("r", 0)
    
    while True:  
            msg = to_gps.readline()  
            if msg.startswith("$GPGGA"):  
                    gps_data = msg.split(",")  
                    lat = gps_data[2]  
    		#print lat
    		lat_compass = gps_data[3]      #<-----------SyntaxError source
    		#print lat_compass
                    lon = gps_data[4]  
    		#print lon
    		lon_compass = gps_data[5]  
    		#print lon_compass
                    break
      
    to_gps.close()  
    conn.close()  
    #print "You are now at latitude %s %s and longitude %s %s" % (lat, lat_compass, lon, lon_compass ) 
    
    
    
    app_lock = e32.Ao_lock()
    app_lock.wait()
    Last edited by wirefree101; 2009-06-05 at 09:08.

  5. #5
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Error Reading lists

    Quote Originally Posted by wirefree101 View Post
    As requested, I am providing the entire code below.
    I requested the error message exactly as it is displayed, not the code, because it might be easier and faster to help you that way (I for one don't have 2 devices handy to test the code and don't really know what it does).

  6. #6
    Regular Contributor
    Join Date
    Aug 2005
    Posts
    200

    Re: Error Reading lists

    Quote Originally Posted by bogdan.galiceanu View Post
    I requested the error message exactly as it is displayed, not the code, because it might be easier and faster to help you that way (I for one don't have 2 devices handy to test the code and don't really know what it does).
    Apologize for the overlook. Below is the precise error generated by the code above:

    Code:
    Traceback (most recent call last):
      File "C:\private\2000b1a5\default.py", line 81, in menu_action
        f()
      File "C:\private\2000b1a5\default.py", line 65, in query_and_exec
        execfile(script_list[index][1].encode('utf-8'), script_namespace.namespace)
      File "e:\python\graphics_gps_3.py", line 46
         lat_compass = gps_data[3]
         ^
     SyntaxError: invalid syntax
    Look forward to a prompt response.

    Best,
    wirefree

  7. #7
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,795

    Re: Error Reading lists

    Appears to me as a small indent error on the line you pointed out. The indentation of the if block should be same. lat_compass = gps_data[3] is not properly indented.

    This might have occured due to use of comments with the same indentation. Tip: Use comments after the code in the same line and not in a new line
    Pankaj Nathani
    www.croozeus.com

Similar Threads

  1. Getting IOException while reading image
    By renuka_anil in forum Mobile Java General
    Replies: 3
    Last Post: 2008-01-10, 11:23
  2. Replies: 15
    Last Post: 2007-10-24, 13:47
  3. Nokia 6234 Reading Bluetooth GPS Stream
    By ravey72 in forum Mobile Java General
    Replies: 0
    Last Post: 2006-09-01, 16:32
  4. Reading given number of bytes with RSocket::Read()
    By luweiewul in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2005-07-15, 05:57
  5. Lists within lists
    By flipflop82 in forum Symbian
    Replies: 0
    Last Post: 2005-02-08, 15:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×