Python Forum

Full Version: Python Errors
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I've been trying to figure it out for the last 4 days - no luck!
(May-23-2017, 09:53 PM)kendias Wrote: [ -> ]I've been trying to figure it out for the last 4 days - no luck!

Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = '5'
>>> type(x)
<type 'str'>
>>> y = 5
>>> type(y)
<type 'int'>
>>> 
Thanks Buran.
I am trying this script to convert from decimal to degrees to use on Google Maps but get errors:
# -*- coding: utf-8 -*-
import webbrowser
import string

def to_degrees(lats, longs):
# Convert string forms from ddmm.mmmm to dd°mm'ss.ss“

   lat_deg = lats[0:2]
   lat_mins = lats[2:4]
   lat_secs = round(float(lats[5:])*60/10000, 2)
   lat_str = lat_deg + u'°'+ lat_mins + string.printable[68] + str(lat_secs) + string.printable[63]

   lon_deg = longs[0:3]
   lon_mins = longs[3:5]
   lon_secs = round(float(longs[6:])*60/10000, 2)
   lon_str = lon_deg + u'°'+ lon_mins + string.printable[68] + str(lon_secs) + string.printable[63]

   return [lat_str, lon_str]


#error
to_degrees(50,50)

TypeErrorTraceback (most recent call last)
<ipython-input-222-1cfff49fb11e> in <module>()
----> 1 to_degrees(50,50)

c:\users\dell\appdata\local\temp\tmpxzjzal.py in to_degrees(lats, longs)
TypeError: 'int' object has no attribute '__getitem__' 
What's the actual traceback? There's no line number there, or any context.
Here is the traceback. It was posted in the main body in my last post.

to_degrees(50,50)

TypeErrorTraceback (most recent call last)
<ipython-input-222-1cfff49fb11e> in <module>()
----> 1 to_degrees(50,50)

c:\users\dell\appdata\local\temp\tmpxzjzal.py in to_degrees(lats, longs)
TypeError: 'int' object has no attribute '__getitem__' 
(May-24-2017, 01:50 PM)kendias Wrote: [ -> ]Thanks Buran.
I am trying this script to convert from decimal to degrees to use on Google Maps but get errors:
# -*- coding: utf-8 -*-
import webbrowser
import string

def to_degrees(lats, longs):
# Convert string forms from ddmm.mmmm to dd°mm'ss.ss“

   lat_deg = lats[0:2]
   lat_mins = lats[2:4]
.........
to_degrees(50,50)

TypeErrorTraceback (most recent call last)
<ipython-input-222-1cfff49fb11e> in <module>()
----> 1 to_degrees(50,50)

c:\users\dell\appdata\local\temp\tmpxzjzal.py in to_degrees(lats, longs)
TypeError: 'int' object has no attribute '__getitem__' 

You are tying to slice integers in your function - what did you expect? You are calling your function with wrong data - your arguments should have been strings in specified format
Thanks.
Now using the data I get from my smartphone GPS to do the same job. Using an app to get the data into my computer. So, have to parse it (as before) to get GPS coordinates. Basically the serial function is replaced by wireless xmission. Sample data:
?><NodeId>1</NodeId><GPS><Latitude>43.75205871</Latitude><Longitude>-79.25402676</Longitude><Accuracy>10.0</Accuracy></GPS><TimeStamp>1495736446846</TimeStamp>
Pages: 1 2 3