Skip to content

Commit

Permalink
Adding pretty print methods to Dmap classes
Browse files Browse the repository at this point in the history
From Issue #2 suggestion, added `__str__` and `__repr__`
for better printing of the object that is being used.
Only dmap classes were changed because inherited classes
will obtain the same attributes for printing of the object
but the class name will be adjusted to be same as the actual class
and not the dmap classes.
  • Loading branch information
Marina Schmidt committed May 16, 2019
1 parent f40c973 commit e13ffec
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions pydarn/io/dmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,16 @@ def __init__(self, dmap_file: Union[str, bytes], data_stream=False):
raise dmap_exceptions.EmptyFileError(self.dmap_file)

def __repr__(self):
return "filename: {filename} cursor: {cursor}"\
" Record number: {rec_num}"\
"total bytes: {total}"
"".format(filename=self.filename,
return "{class_name}({filename}, {cursor}, {rec_num}, {total})"\
"".format(class_name=self.__class__.__name__,
filename=self.dmap_file,
cursor=self.cursor,
total=self.dmap_end_bytes,
rec_num=self.rec_num)


def __str__(self):
return "Prepared to read: {filename} at cursor: {cursor} "\
return "Reading from {filename} at cursor: {cursor} "\
"record number: {rec_num} with"\
" a total number of bytes: {total_bytes}"\
"".format(filename=self.dmap_file,
Expand Down Expand Up @@ -865,15 +864,15 @@ def __init__(self, dmap_records: List[dict] = [], filename: str = ""):
pydarn_logger.debug("Initiating DmapWrite")

def __repr__(self):
return "filename: {filename} Record number: {rec_num}"\
"".format(filename=self.filename,
rec_num=self.rec_num)
return "{class_name}({filename}, {rec_num})"\
"".format(class_name=self.__class__.__name__,
filename=self.filename,
rec_num=self.rec_num)

def __str__(self):
return "Prepared to write: {filename} at "\
"record number: {rec_num}"\
"".format(filename=self.filename,
rec_num=self.rec_num)
return "Writing to filename: {filename} at record number: {rec_num}"\
"".format(filename=self.filename,
rec_num=self.rec_num)

# HONEY BADGER method: Because dmap just don't care
def write_dmap(self, filename: str = ""):
Expand Down

0 comments on commit e13ffec

Please sign in to comment.