Python Forum
Formating for __repr__
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formating for __repr__
#3
It would help if we could see the data you are trying to format. It looks from your desired output that position and velocity are tuples of the three dimensional components of position and velocity. You will have to format each tuple separately, and then combine the results in with the formatting of any non-tuple data.
position = (801, 23, 2.718281828)
position_text = '({:3g}, {:3g}, {:3g})'.format(*position)
The * syntax converts a sequence into a sequence of parameters.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
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,982 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