I am writing a python script that will accept a dot-delimited version number. It will split this string into individual components (using period (.
) as a delimiter). My script supports up to 4 components (e.g. 1.2.3.4
). However, the user may specify less or more components than 4 and my script needs to be able to handle it.
If less than 4, the list that I get back from string.split()
needs to be resized to 4 and missing components initialized to the string "0"
. If greater than 4, just truncate the elements past the 4th component.
The truncation is easy, I would just splice the list. However, I'm not sure how to perform the resize up to 4 elements. Is there a pythonic way of doing this, or do I need to hand-write a bunch of logic to do it?
I'm using Python 3.2.