This should get you started:
>>> import re
>>> formula = "P = V*I*cos(2*pi*f)"
>>> variables = re.findall('[a-zA-Z]+' , formula)
['P', 'V', 'I', 'cos', 'pi', 'f']
>>> special = ['cos', 'pi']
>>> variables = [v for v in variables if v not in special]
['P', 'V', 'I', 'f']
From here you can improve the regular expression to account for more complex variable names (ex: V1)