Skip to content
Advertisement

Tag: format

Python Regex groups causing index errors

So, my interpereter is complaining about IndexError: Replacement index 1 out of range for positional args tuple when calling re.group(#) or re.groups() under specific circumstances. It is meant to return a phone number, such as +1 (555) 555-5555 Here is the regex used, as it is declared elsewhere: Here is the code causing the issues: Full Traceback: Answer You have

Python string format

I have defined the string variable value=“c:/program files/tm su/usr” I need to use this variable in another string like Bashcmd=“Override project={value}” I tried adding the rf option like this …

Converting from float to percentage

I would like to convert a decimal number (say 0.33333) to percentage (expected answer 33.33%) I used the following x = 0.3333 print(format(x,’.2%’)) which gives indeed 33.33% However, the result …

Advertisement