Formatting Integer Numbers

Formatting Integer Numbers

isocam
Collaborator Collaborator
378 Views
1 Reply
Message 1 of 2

Formatting Integer Numbers

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following line of code in a Python script:

 

#PartQuantity = "{}".format(len(design.rootComponent.allOccurrencesByComponent(component)))

 

At present, the output of a number, in this case the quantity in an assembly, is....

 

1---

12--

123-

1234

 

I need the numbers formatting so that the output is....

---1

--12

-123

1234

 

(The character "-" represents a space, I do not need this character in the output)

 

Can anybody update the line of code to allow me to do this?

 

Many thanks in advance!

 

Darren

0 Likes
Accepted solutions (1)
379 Views
1 Reply
Reply (1)
Message 2 of 2

CADacombs
Enthusiast
Enthusiast
Accepted solution
PartQuantity = "{:>4}".format(len(design.rootComponent.allOccurrencesByComponent(component)))

or

PartQuantity = "{}".format(len(design.rootComponent.allOccurrencesByComponent(component))).rjust(4)