|
3 | 3 | Examples of use: |
4 | 4 |
|
5 | 5 | >>> import phonenumbers |
| 6 | +>>> from phonenumbers.util import prnt # equivalent to Py3k print() |
6 | 7 | >>> x = phonenumbers.parse("+442083661177", None) |
7 | | ->>> print x |
| 8 | +>>> prnt(x) |
8 | 9 | Country Code: 44 National Number: 2083661177 Leading Zero: False |
9 | 10 | >>> type(x) |
10 | 11 | <class 'phonenumbers.phonenumber.PhoneNumber'> |
|
15 | 16 | >>> str(phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.E164)) |
16 | 17 | '+442083661177' |
17 | 18 | >>> y = phonenumbers.parse("020 8366 1177", "GB") |
18 | | ->>> print y |
| 19 | +>>> prnt(y) |
19 | 20 | Country Code: 44 National Number: 2083661177 Leading Zero: False |
20 | 21 | >>> x == y |
21 | 22 | True |
22 | 23 | >>> |
23 | 24 | >>> formatter = phonenumbers.AsYouTypeFormatter("US") |
24 | | ->>> print formatter.input_digit("6") |
| 25 | +>>> prnt(formatter.input_digit("6")) |
25 | 26 | 6 |
26 | | ->>> print formatter.input_digit("5") |
| 27 | +>>> prnt(formatter.input_digit("5")) |
27 | 28 | 65 |
28 | | ->>> print formatter.input_digit("0") |
| 29 | +>>> prnt(formatter.input_digit("0")) |
29 | 30 | 650 |
30 | | ->>> print formatter.input_digit("2") |
| 31 | +>>> prnt(formatter.input_digit("2")) |
31 | 32 | 650-2 |
32 | | ->>> print formatter.input_digit("5") |
| 33 | +>>> prnt(formatter.input_digit("5")) |
33 | 34 | 650-25 |
34 | | ->>> print formatter.input_digit("3") |
| 35 | +>>> prnt(formatter.input_digit("3")) |
35 | 36 | 650-253 |
36 | | ->>> print formatter.input_digit("2") |
| 37 | +>>> prnt(formatter.input_digit("2")) |
37 | 38 | 650-2532 |
38 | | ->>> print formatter.input_digit("2") |
| 39 | +>>> prnt(formatter.input_digit("2")) |
39 | 40 | (650) 253-22 |
40 | | ->>> print formatter.input_digit("2") |
| 41 | +>>> prnt(formatter.input_digit("2")) |
41 | 42 | (650) 253-222 |
42 | | ->>> print formatter.input_digit("2") |
| 43 | +>>> prnt(formatter.input_digit("2")) |
43 | 44 | (650) 253-2222 |
44 | 45 | >>> |
45 | 46 | >>> text = "Call me at 510-748-8230 if it's before 9:30, or on 703-4800500 after 10am." |
46 | 47 | >>> for match in phonenumbers.PhoneNumberMatcher(text, "US"): |
47 | | -... print match |
| 48 | +... prnt(match) |
48 | 49 | ... |
49 | 50 | PhoneNumberMatch [11,23) 510-748-8230 |
50 | 51 | PhoneNumberMatch [51,62) 703-4800500 |
51 | 52 | >>> for match in phonenumbers.PhoneNumberMatcher(text, "US"): |
52 | | -... print phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164) |
| 53 | +... prnt(phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164)) |
53 | 54 | ... |
54 | 55 | +15107488230 |
55 | 56 | +17034800500 |
|
0 commit comments