Python Forum
Formating for __repr__
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formating for __repr__
#5
I mostly have it now. Thought I would follow up for anyone else and to see how to align it all correctly. Here's the code:

formatted = '{0!s:6s},{1!s:6s},{2!s:6s}'.format(mass, position, velocity)
Input


str(melon) == "3kg (0,6.37e+06,0) (0,0,0)"

I get 3kg (0,6.37e+06,0) (0,0,0), which is correct.


When I pass this
str(earth) == "5.97e+24kg (0,0,0) (0,0,0)"

I get 5.9736kg (0,0,0) (0,0,0), which you can see is not correct.
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