What's the best way to format a phone number in Python?

后端 未结 4 1248
慢半拍i
慢半拍i 2020-12-01 20:32

If all I have is a string of 10 or more digits, how can I format this as a phone number?

Some trivial examples:

555-5555
555-555-5555
1-800-555-5555
         


        
4条回答
  •  独厮守ぢ
    2020-12-01 21:11

    for library: phonenumbers (pypi, source)

    Python version of Google's common library for parsing, formatting, storing and validating international phone numbers.

    The readme is insufficient, but I found the code well documented.

提交回复
热议问题