Should I Use DAO Objects In Python __init__?

36
August 19, 2018, at 6:20 PM

In python, which is better:

class MyAPI:
    def __init__(self):
       self.dao = MyDAO()
    def getsomething(self):
       something = self.dao.grabSomething()
       newsomething = operateon(something)
       return newsomething
    def getsomethingelse()
       somethingelse = self.dao.grabSomethingElse()
       newsomethingelse = operateon(somethingelse)
       return newsomethingelse

OR

class MyAPI:
    def getsomething(self):
       dao = MyDAO()
       something = dao.grabSomething()
       newsomething = operateon(something)
       return newsomething
    def getsomethingelse()
       dao = MyDAO()
       somethingelse = dao.grabSomethingElse()
       newsomethingelse = operateon(somethingelse)
       return newsomethingelse

I am a complete python noob coming from a java spring background and I am really trying to understand the difference here.

READ ALSO
PyQt5 How to identify and grab data from a QT combobox that has been created along with other combobox using a function

PyQt5 How to identify and grab data from a QT combobox that has been created along with other combobox using a function

I wrote a script that automatically creates a QT "object" made up of a category label, a combobox_1 with possible attributes, a push button and a combobox_2 to list all values available for the attribute selectedthe script creates as many of these "objects"...

32
Pandas MultiIndex dataframe replace min and max with 0

Pandas MultiIndex dataframe replace min and max with 0

I have a dataframe with multiindex and trying to find a way to replace values that are equal to min or max with 0 within each level = 0For example:

69
Get records for a list of multiple entities on Wikidata

Get records for a list of multiple entities on Wikidata

I am mapping multiple entities (Q entries) in Wikidata for which I need the same record of properties (P entries)For sake of this question, say I have a list of five Wikidata entities (Q1, Q2, Q3, Q4, Q5) for which I want to retrieve the same property...

59
Perzeptron algorithm - code error - Python 3

Perzeptron algorithm - code error - Python 3

I am working through the German book "Machine Learning with Python" by Sebastian RashkaI am using anaconda and spyder (including ipython console) on a windows machine

48