I'm pretty sure I'm heavily abusing Python and I require assistance in fixing it:
I've worked with Java for the past year for school projects and just fiddled around with python a bit in the last few months.
I'm in the middle of a project in python and I really feel like I'm abusing the language and writing as if I'm using Java.
For example: I'm using a specific engine that analyzes some data for me. Since it returns the result in a specific format, I wrote a wrapper object handles the result data (in this case it receives a json and takes the relevant pieces from it).
Since I wanted there to be an abstract Result
type for me to work with in the future, I created the following class which is effectively equivalent to a Java abstract class:
class STTResult:
def get_text(self):
raise NotImplementedError("This is an abstract class")
def get_confidence(self):
raise NotImplementedError("This is an abstract class")
def get_intent(self):
raise NotImplementedError("This is an abstract class")
def get_entities(self):
raise NotImplementedError("This is an abstract class")
and then the concrete class:
class WitResult(STTResult):
def __init__(self,json_result):
self.text = json_result["_text"]
self.confidence = json_result["outcomes"][0]["confidence"]
self.intent = json_result["outcomes"][0]["intent"]
self.entities = json_result["outcomes"][0]["entities"]
def get_text(self):
return self.text
def get_confidence(self):
return self.confidence
def get_intent(self):
return self.intent
def get_entities(self):
return self.entities
I'm quite sure this is not pythonic. So how can I get out of the Java, C++, C# mindset and into the python mindset?
Clarification: It's not that I don't know the language / syntax of python. I'm aware of most of the basic features and modules.
json_result["outcomes"][0]
that is very useful on its own. If you don't need more, don't write more.