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