Skip to content

Commit

Permalink
improved __str__ and __repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyman192 committed Dec 11, 2018
1 parent de97810 commit 913854a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions BIDSHandler/BIDSFolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def scans(self):
scan_list = []
for project in self.projects:
scan_list.extend(project.scans)
return scan_list

@property
def sessions(self):
Expand Down Expand Up @@ -161,4 +162,10 @@ def __getitem__(self, item):
return self.project(item)

def __repr__(self):
return '<BIDSFolder, {0} project{1}, @ {2}>'.format(
len(self.projects),
('s' if len(self.projects) > 1 else ''),
self.path)

def __str__(self):
return "BIDS folder containing {0} projects".format(len(self.projects))
7 changes: 7 additions & 0 deletions BIDSHandler/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ def __getitem__(self, item):
return self.subject(item)

def __repr__(self):
return '<Project, ID: {0}, {1} subject{2}, @ {3}>'.format(
self.ID,
len(self.subjects),
('s' if len(self.subjects) > 1 else ''),
self.path)

def __str__(self):
output = []
output.append('ID: {0}'.format(self.ID))
output.append('Number of subjects: {0}'.format(len(self.subjects)))
Expand Down
3 changes: 3 additions & 0 deletions BIDSHandler/Scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,7 @@ def __eq__(self, other):
(self.project._id == other.project._id))

def __repr__(self):
return '<Scan, @ {0}>'.format(self.raw_file)

def __str__(self):
return self.raw_file_relative
7 changes: 7 additions & 0 deletions BIDSHandler/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ def __iter__(self):
return iter(self._scans)

def __repr__(self):
return '<Session, ID: {0}, {1} scan{2}, @ {3}>'.format(
self.ID,
len(self.scans),
('s' if len(self.scans) > 1 else ''),
self.path)

def __str__(self):
output = []
output.append('ID: {0}'.format(self.ID))
output.append('Number of scans: {0}'.format(len(self.scans)))
Expand Down
7 changes: 7 additions & 0 deletions BIDSHandler/Subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ def __getitem__(self, item):
return self.session(item)

def __repr__(self):
return '<Subject, ID: {0}, {1} session{2}, @ {3}>'.format(
self.ID,
len(self.sessions),
('s' if len(self.sessions) > 1 else ''),
self.path)

def __str__(self):
output = []
output.append('ID: {0}'.format(self.ID))
output.append('Age: {0}'.format(self.age))
Expand Down

0 comments on commit 913854a

Please sign in to comment.