From 9d04a0018c0cef2d71fab39f2e9873f6b0440c6c Mon Sep 17 00:00:00 2001 From: Don Cross Date: Sun, 14 Jun 2020 21:31:07 -0400 Subject: [PATCH] Python: improved Time repr. Added Vector repr, str support. --- generate/template/astronomy.py | 8 +++++++- source/python/astronomy.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index 5e1db5e9..ace9fd28 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -120,6 +120,12 @@ class Vector: self.z = z self.t = t + def __repr__(self): + return 'Vector({}, {}, {}, {})'.format(self.x, self.y, self.z, str(self.t)) + + def __str__(self): + return '({}, {}, {}, {})'.format(self.x, self.y, self.z, str(self.t)) + def Length(self): """Returns the length of the vector in AU.""" return math.sqrt(self.x**2 + self.y**2 + self.z**2) @@ -554,7 +560,7 @@ class Time: return Time(self.ut + days) def __repr__(self): - return 'astronomy.Time(' + repr(self.ut) + ')' + return 'Time(' + str(self) + ')' def __str__(self): millis = round(self.ut * 86400000.0) diff --git a/source/python/astronomy.py b/source/python/astronomy.py index 52b7bdec..87cb2086 100644 --- a/source/python/astronomy.py +++ b/source/python/astronomy.py @@ -120,6 +120,12 @@ class Vector: self.z = z self.t = t + def __repr__(self): + return 'Vector({}, {}, {}, {})'.format(self.x, self.y, self.z, str(self.t)) + + def __str__(self): + return '({}, {}, {}, {})'.format(self.x, self.y, self.z, str(self.t)) + def Length(self): """Returns the length of the vector in AU.""" return math.sqrt(self.x**2 + self.y**2 + self.z**2) @@ -554,7 +560,7 @@ class Time: return Time(self.ut + days) def __repr__(self): - return 'astronomy.Time(' + repr(self.ut) + ')' + return 'Time(' + str(self) + ')' def __str__(self): millis = round(self.ut * 86400000.0)