Does anyone know why this doesn't work? its meant to convert degrees, min, secs to decimal degrees. It should be simple right - but I'm very new to python (yesterday...) - class DMStoDD:
-
def__init__(self, degrees, min, sec):
-
self.degrees = abs(degrees) % 360
-
self.minute = abs(min) % 60
-
self.second = abs(sec) % 60
-
def DD:
-
self.degrees = (self.degrees) % 360
-
self.minute = self.minute/60
-
self.seconds = self.seconds/3600
-
def AsList(self):
-
print [self.degrees, self.minute, self.seconds]
also how do I run my class?
You also have to add (self) to DD if you want it to be a function that is a member of the class. This is what I get using your original post: - class DMStoDD:
-
def __init__(self, degrees, mins, sec):
-
## anything less than 360 will yield the same number
-
self.degrees = abs(degrees) % 360
-
-
## "min" is a reserved name==minimum
-
self.minute = abs(mins) % 60
-
self.seconds = abs(sec) % 60
-
-
def DD(self): ## same as __init__ calcs
-
self.degrees = (self.degrees) % 360
-
self.minute = self.minute/60
-
self.seconds = self.seconds/3600
-
-
def AsList(self):
-
print [self.degrees, self.minute, self.seconds]
-
-
DS = DMStoDD(29, 12, 30)
-
DS.AsList() ## prints [29, 12, 30]
-
DS = DMStoDD(390, 12, 30)
-
DS.AsList() ## prints [30, 12, 30]
6 9418 bvdet 2,851
Recognized Expert Moderator Specialist
What would the input look like? Why are you using "modulo 360" for self.degrees? A degree is 1 degree, a minute is 1/60 of a degree, and a second is 1/3600 of a degree. If you intend "DD" to be a method, you need an argument tuple with "self" in it. def DD(self): - >>> degrees, minutes, seconds = 30, 25, 15
-
>>> decdeg = degrees+minutes/60.+seconds/3600.
-
>>> decdeg
-
30.420833333333334
-
>>>
To run it, create an instance by calling the class like a function: obj = DMStoDD(degrees, minutes, seconds) dwblas 626
Recognized Expert Contributor
Figure it out on paper first and use google if you can't get some of the calcs to work out.
well I got it to work, there was a space missing between def and __init
the problem is I get this as a result <__main__.DDtoDMS object at 0x0216D4B0> when I want a number format (10.006)
bvdet 2,851
Recognized Expert Moderator Specialist
Add a __str__ method to the class definition, and print obj , where obj is an instance of DMStoDD, will write whatever you want to stdout.
dwblas 626
Recognized Expert Contributor
You also have to add (self) to DD if you want it to be a function that is a member of the class. This is what I get using your original post: - class DMStoDD:
-
def __init__(self, degrees, mins, sec):
-
## anything less than 360 will yield the same number
-
self.degrees = abs(degrees) % 360
-
-
## "min" is a reserved name==minimum
-
self.minute = abs(mins) % 60
-
self.seconds = abs(sec) % 60
-
-
def DD(self): ## same as __init__ calcs
-
self.degrees = (self.degrees) % 360
-
self.minute = self.minute/60
-
self.seconds = self.seconds/3600
-
-
def AsList(self):
-
print [self.degrees, self.minute, self.seconds]
-
-
DS = DMStoDD(29, 12, 30)
-
DS.AsList() ## prints [29, 12, 30]
-
DS = DMStoDD(390, 12, 30)
-
DS.AsList() ## prints [30, 12, 30]
thanks for everyones help. It works now, I think the main problem was I was using python 3 not 2. Its a bit strange that nothing seems to work in python 3 - sort, sorted doesn't work either. I kept getting DMStoDD is not defined. But it works in python 2 now. The only thing I can't get is to limit the values degrees(0-360), minutes(0-60)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dean G |
last post by:
I need to compare two values. one from a text field 'bid' and the other
from a field in an sql server database 'maxbid'.
The problem is the column in the database has decimal as its data type...
|
by: JenHu |
last post by:
Hi all,
I have to read from a text file and generate values and insert to
database.
But first of all, when the text file contains '0000000000', I received
a sEfundAmt value = 0D instead of 0.0...
|
by: Allerdyce.John |
last post by:
Do I need to convert string to integer in python? or it will do it for
me (since dynamic type)?
In my python script, I have this line:
x /= 10;
when i run it, I get this error:
TypeError:...
|
by: mlafarlett |
last post by:
In the example below, the 'convert.ToDecimal' removes the trailing 5.
I'd
like to get the number, in tact, moved to the decimal variable. Any
help would be greatly appreciated.
Dim dcml As...
|
by: Lance |
last post by:
Hi all,
Below is a funtion that converts a Lat or Lon coordinate (as a Double) to a
string of Degrees, Minutes and Seconds. It's based on an MS Exmaple for VBA
found here...
|
by: Leo jay |
last post by:
i'd like to implement a class template to convert binary numbers to
decimal at compile time.
and my test cases are:
BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535));...
|
by: cmdolcet69 |
last post by:
Public ArrList As New ArrayList
Public bitvalue As Byte()
Public Sub addvalues()
Dim index As Integer
ArrList.Add(100)
ArrList.Add(200)
ArrList.Add(300)
ArrList.Add(400)
ArrList.Add(500)
|
by: karthickbabu |
last post by:
Hi
In my application i want to convert integer to decimal. I get a input and using convert function to convert into decimal. But it shows as it self. My code like as below, Is any wrong in...
|
by: arial |
last post by:
Hi all,
I have a sql .bak file which i need to convert into xml file.
can someone help with this?
pointing out to some tutorial or some suggetion on how to start?
Thak you,
|
by: lenora |
last post by:
How to convert string to decimal ?
input - output
45 - 45.00
45.5 - 45.50
45.51 - 45.51
Thank you in advance
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| | |