Yes, it is a variable which is simply a measurement obtained from an object (hence float), and yes, this is just an example. Try it with 0400 or 04000. OTOH, it works fine if there is no leading 0 such as 40, 400, 4000 etc.
If this is for the cuttinglist cvs exprt, I was having a look at that as well
does this suffice?:
def SF(num):
#strips leading/trailing zeros plus decimal point from float if possible
#returns string
stripped_zero = "{}".format(num).strip("0")
stripped_point = stripped_zero.strip(".")
return stripped_point
Oh, I’m just being stubborn, I always try to create a general case assuming that one never knows where the data is coming from… one function that would intelligently strip leading and trailing zeroes but preserve the numbers…
Your above definition doesn’t work for my case because for 400 it returns 4…
The following works fine if I assume no leading zeroes -
def SF(num):
#strips trailing zeros plus decimal point from float if possible
#preserves trailing zeros to left of decimal. returns string
num_str="{}".format(num)
if "." in num_str:
num_parts=num_str.split(".")
num_str,back=num_parts
back=back.rstrip("0")
if back: num_str="{}.{}".format(num_str,back)
return num_str
Meaning: numerical literal starting with a 0 and followed by at least one octdigit between 0 and 7 inclusive us an octal integer. That is the last part if the first line.
It also could be a capital o followed by at least one octdigit (middle part of first line).
Or it could start with a zero, followed by an either-cased o-letter and then at least one octdigit, making it an octinteger according the first form of the first line.
Try print(090). You’ll get an exception…
Meh, typing on the phone gives for funky explanation, in short octal integers start with one or two zeroes or a zero and an o-letter. After tgat start at least one octal digit in the range 0-7 inclusive.