Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How you think we might want to represent a constellation as a string? I\'m prett

ID: 3726195 • Letter: H

Question

How you think we might want to represent a constellation as a string?

I'm pretty sure Instrument has a __str__ method, so you could just call that for each instrument in the constellation

but I don't know how to implement that

import _instruments

class Constellation(object):

"""Manage and analyze data from multiple pysat Instruments.

FIXME document this.

"""

def __init__(self, instruments=None, name=None):

if instruments and name:

raise ValueError('When creating a constellation, please specify '

'a list of instruments or a name, not both.')

elif instruments and not hasattr(instruments, '__getitem__'):

raise ValueError('Constellation: Instruments must be list-like.')

elif not (name or instruments):

raise ValueError('Constellation: Cannot create empty '

   'constellation.')

if instruments:

self.instruments = instruments

else:

# TODO Implement constellation lookup by name.

raise NotImplementedError()

def __getitem__(self, *args, **kwargs):

return self.instruments.__getitem__(*args, **kwargs)

def __str__(self):

# TODO Implement conversion to string

raise NotImplementedError()

def __repr__(self):

# TODO Implement __repr__

raise NotImplementedError()

def add(self, bounds1, label1, bounds2, label2, bin3, label3,

data_label):

# TODO Implement signal addition.

raise NotImplementedError()

def difference(self, instrument1, instrumet2, data_labels):

# TODO Implement signal difference.

raise NotImplementedError()

Explanation / Answer

import _instruments class Constellation(object): """Manage and analyze data from multiple pysat Instruments. FIXME document this. """ def __init__(self, instruments=None, name=None): if instruments and name: raise ValueError('When creating a constellation, please specify ' 'a list of instruments or a name, not both.') elif instruments and not hasattr(instruments, '__getitem__'): raise ValueError('Constellation: Instruments must be list-like.') elif not (name or instruments): raise ValueError('Constellation: Cannot create empty ' 'constellation.') if instruments: self.instruments = instruments else: # TODO Implement constellation lookup by name. raise NotImplementedError() def __getitem__(self, *args, **kwargs): return self.instruments.__getitem__(*args, **kwargs) def __str__(self): string = '' for instrument in self.instruments: string += str(instrument) string += ' ' return string def __repr__(self): # TODO Implement __repr__ raise NotImplementedError() def add(self, bounds1, label1, bounds2, label2, bin3, label3, data_label): # TODO Implement signal addition. raise NotImplementedError() def difference(self, instrument1, instrumet2, data_labels): # TODO Implement signal difference. raise NotImplementedError()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote