Skip to content

Commit 067f936

Browse files
committed
Add examples to docstring
1 parent ce883df commit 067f936

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

python/phonenumbers/__init__.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,55 @@
1-
"""Python phone number parsing and formatting library"""
1+
"""Python phone number parsing and formatting library
2+
3+
Examples of use:
4+
5+
>>> import phonenumbers
6+
>>> x = phonenumbers.parse("+442083661177", None)
7+
>>> print x
8+
Country Code: 44 National Number: 2083661177 Leading Zero: False
9+
>>> phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.NATIONAL)
10+
u'020 8366 1177'
11+
>>> phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.INTERNATIONAL)
12+
u'+44 20 8366 1177'
13+
>>> phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.E164)
14+
u'+442083661177'
15+
>>> y = phonenumbers.parse("020 8366 1177", "GB")
16+
>>> print y
17+
Country Code: 44 National Number: 2083661177 Leading Zero: False
18+
>>> x == y
19+
True
20+
>>>
21+
>>> formatter = phonenumbers.AsYouTypeFormatter("US")
22+
>>> print formatter.input_digit("6")
23+
6
24+
>>> print formatter.input_digit("5")
25+
65
26+
>>> print formatter.input_digit("0")
27+
(650
28+
>>> print formatter.input_digit("2")
29+
(650) 2
30+
>>> print formatter.input_digit("5")
31+
(650) 25
32+
>>> print formatter.input_digit("3")
33+
(650) 253
34+
>>> print formatter.input_digit("2")
35+
650-2532
36+
>>> print formatter.input_digit("2")
37+
(650) 253-22
38+
>>> print formatter.input_digit("2")
39+
(650) 253-222
40+
>>> print formatter.input_digit("2")
41+
(650) 253-2222
42+
>>>
43+
>>> text = "Call me at 510-748-8230 some time after 9:30."
44+
>>>
45+
>>> text = "Call me at 510-748-8230 if it's before 9:30, or on 703-4800500 after 10am."
46+
>>> for match in phonenumbers.PhoneNumberMatcher(text, "US"):
47+
... print match
48+
...
49+
PhoneNumberMatch [11,23) 510-748-8230
50+
PhoneNumberMatch [51,62) 703-4800500
51+
52+
"""
253

354
# Licensed under the Apache License, Version 2.0 (the "License");
455
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)