Python Forum
Formating for __repr__
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formating for __repr__
#4
Maybe it would help if I give you the entire __repr__ function.  The data being passed as parameters is mass = 3, position = (0,6.37e+06,0), and velocity = (0,0,0)
def __repr__(self):
        #Representation Call
        #"3kg (0,6.37e+06,0) (0,0,0)"
        formatted = '{1:.6f},({1:.6f},{1:.6f},{1:.6f}),({1:.6f},{1:.6f},{1:.6f})'.format(self.mass, self.position, self.velocity)
        
        print(formatted) #This was for testing. 
        return formatted
Reply


Messages In This Thread
Formating for __repr__ - by Steven - Apr-22-2017, 05:08 AM
RE: Formating for __repr__ - by volcano63 - Apr-22-2017, 10:44 AM
RE: Formating for __repr__ - by ichabod801 - Apr-22-2017, 10:45 AM
RE: Formating for __repr__ - by Steven - Apr-22-2017, 04:18 PM
RE: Formating for __repr__ - by Steven - Apr-23-2017, 04:08 PM
RE: Formating for __repr__ - by ichabod801 - Apr-23-2017, 11:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Display Formating Jrvelandia 2 2,929 Apr-23-2018, 11:54 PM
Last Post: Jrvelandia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020