There's got to be an easy way to do this

Brad Bollenbach bbollenbach at homenospam.com
Thu Jul 5 17:31:07 EDT 2001


Consider the underlying problem here before going any further.

Generally speaking "data" isn't stored formatted. "Information" is data that
has /been/ formatted. In other words, your data model (whether flat file, or
database), should store phone numbers as:

1235554444

not

(123) 555 - 4444

So by the sounds of it, if you have to do some trickery just to extract
_only digits_ out of  a stored phone number, you might want to fix your data
model before you fix your code.

"Lindstrom Greg - glinds" <Greg.Lindstrom at acxiom.com> wrote in message
news:mailman.994350130.18544.python-list at python.org...
> I am reading in a phone number field and would like to throw away
everything
> except the digits.  Being an old C programmer, I know how I would do this.
> Even with my limited knowledge of Python, I know how I would do it:
>
> stripped_phone=''
> for c in phone_number:
> if c in digits:
> stripped_phone += c
>
> but with all of the data structure support native to Python, I'm sure
there
> is "an obvious way" to do it (perhaps it's because I'm not Dutch:-).
>
> Greg Lindstrom
> Acxiom Corporation,                    mail: CWY10011149
> InfoBase Products Development                  office: (501) 342-1626
> 301 Industrial Blvd, Conway, AR, 72032     fax:     (501) 336-3911
> email: Greg.Lindstrom at acxiom.com
>
> "When the solution is simple, God has spoken"
>
>                                                             Albert
Einstein
>
>
>





More information about the Python-list mailing list