Python Forum
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Errors
#21
I've been trying to figure it out for the last 4 days - no luck!
Reply
#22
(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'>
>>> 
Reply
#23
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__' 
Reply
#24
What's the actual traceback? There's no line number there, or any context.
Reply
#25
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__' 
Reply
#26
(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
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#27
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>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  When does Python detect Errors? stamp1t 1 439 Oct-21-2023, 05:53 PM
Last Post: deanhystad
  Rmarkdown opened by python code - errors Rav013 0 2,085 Apr-27-2021, 03:13 PM
Last Post: Rav013
  Python Request Errors PythonNoob1998 7 3,922 Jan-07-2021, 05:18 PM
Last Post: buran
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 4,443 Feb-08-2020, 07:21 PM
Last Post: jamesphopper
  Python stops without errors shahgourav 4 2,760 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Can the comments produce errors in python? newbieAuggie2019 9 4,275 Nov-26-2019, 12:19 AM
Last Post: micseydel
  Running into errors when installing pip and pip3 on python 2.7 and python 3.6 tej7gandhi 1 2,836 May-05-2019, 10:37 PM
Last Post: snippsat
  Does Python sqlite3 detect connection errors zatlas1 6 3,958 Jan-18-2019, 06:02 AM
Last Post: zatlas1
  Errors in Python dttomoum 1 2,697 May-23-2018, 08:57 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020