On Wed, Feb 10, 2010 at 12:19 PM, <a href="mailto:ssteinerX@gmail.com">ssteinerX@gmail.com</a> <<a href="mailto:ssteinerx@gmail.com">ssteinerx@gmail.com</a>> wrote:<br>> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote:<br>
>> On 2010-02-10, <a href="mailto:python@bdurham.com">python@bdurham.com</a> <<a href="mailto:python@bdurham.com">python@bdurham.com</a>> wrote:<br>>><br>>> [regardning "picture" output format specifiers]<br>
>><br>>>> I was thinking that there was a built-in function for this<br>>>> common(?) use case<br>>><br>>> I haven't seen that paradigm since my one-and-only exposure to<br>>> COBOL in a class I took back in 1979. Is the "picture" thing<br>
>> commonly used in other places than COBOL?<br><snip><br>> Haven't you ever had to get a e.g. a phone number or social security number from user input?<br><br>If I have a GUI, I can just put 3 separate length-limited text fields and then I only have to<div>
check that the input is numerical and each field is of the right length; no fiddling with</div><div>punctuation or manual separation into fields; or more likely, there's already a phone</div><div>number widget! In other words, I won't care about the punctuation characters anyway.</div>
<div><br>If I don't have a GUI:<br>(1) my program is probably not for end-users, so I can be less user-friendly and more dictatorial about the required format<br>(2) or it's munging mediocre data from a DB and I need to be more error-tolerant that picture formatting would allow</div>
<div>(3) in any case, it's not *that* hard to do without picture formatting (although it might get tedious after a while,</div><div>probably hence why some languages in just the right niche indeed offer picture formatting):</div>
<div><br><font class="Apple-style-span" face="'courier new', monospace">phone_parts = input("Phone number?: ").replace('(', '').replace(')', '').split('-')<br>if not all(part.isdigit() for part in phone_parts) or [3,3,4] != map(len, phone_parts):<br>
#error message to user</font><br><br>Stricter validation would either be user-unfriendly or is left as an exercise to the reader.<br><br>Cheers,<br>Chris<br>--<br><a href="http://blog.rebertia.com">http://blog.rebertia.com</a></div>