<div dir="ltr">Hello,<br><br>I often need to parse strings which contain a mix of characters, integers and floats, the C-language scanf function is very practical for this purpose.<br>I've been looking for such a feature and I have been quite surprised to find that it has been discussed as far back as 2001 but never implemented. The recommended approach seems to be to use split and then atoi or atof or to use regex and then atoi and atof. Both approaches seem to be a lot less natural and much more cumbersome than scanf. If python already has a % string operator that behaves like printf, why not implement either a %% or << string operator to behave like scanf, use could be like the followng:<br>
<br>a, b, c = "%d %f %5c" %% "1 2.0 abcde"<br><br>or <br><br>a, b, c = "%d %f %5c" << "1 2.0 abcde"<br><br>%% is closer to the % operator<br><br><< seems more intuitive<br>
<br>either of this methods seems to me much simpler than:<br><br>lst = "1 2;0 abcde".split()<br>a = int(lst[0])<br>b = float(lst[1])<br>c = lst[2]<br><br>or even worse when using regular expressions to parse such simple input.<br>
<br>I like python because it is concise and easy to read and I really think it could use such an operator.<br><br>I know this has been discussed before and many times, but all previous threads I found seem to be dead and I would like to invite further investigation of this topic.<br>
<br>Best Regards,<br><br>André M. Descombes<br></div>