Skip to content

Commit d32f784

Browse files
committed
Use prnt() for Python 2/3 print compatibility
1 parent c15fd9c commit d32f784

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

python/phonenumbers/__init__.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Examples of use:
44
55
>>> import phonenumbers
6+
>>> from phonenumbers.util import prnt # equivalent to Py3k print()
67
>>> x = phonenumbers.parse("+442083661177", None)
7-
>>> print x
8+
>>> prnt(x)
89
Country Code: 44 National Number: 2083661177 Leading Zero: False
910
>>> type(x)
1011
<class 'phonenumbers.phonenumber.PhoneNumber'>
@@ -15,41 +16,41 @@
1516
>>> str(phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.E164))
1617
'+442083661177'
1718
>>> y = phonenumbers.parse("020 8366 1177", "GB")
18-
>>> print y
19+
>>> prnt(y)
1920
Country Code: 44 National Number: 2083661177 Leading Zero: False
2021
>>> x == y
2122
True
2223
>>>
2324
>>> formatter = phonenumbers.AsYouTypeFormatter("US")
24-
>>> print formatter.input_digit("6")
25+
>>> prnt(formatter.input_digit("6"))
2526
6
26-
>>> print formatter.input_digit("5")
27+
>>> prnt(formatter.input_digit("5"))
2728
65
28-
>>> print formatter.input_digit("0")
29+
>>> prnt(formatter.input_digit("0"))
2930
650
30-
>>> print formatter.input_digit("2")
31+
>>> prnt(formatter.input_digit("2"))
3132
650-2
32-
>>> print formatter.input_digit("5")
33+
>>> prnt(formatter.input_digit("5"))
3334
650-25
34-
>>> print formatter.input_digit("3")
35+
>>> prnt(formatter.input_digit("3"))
3536
650-253
36-
>>> print formatter.input_digit("2")
37+
>>> prnt(formatter.input_digit("2"))
3738
650-2532
38-
>>> print formatter.input_digit("2")
39+
>>> prnt(formatter.input_digit("2"))
3940
(650) 253-22
40-
>>> print formatter.input_digit("2")
41+
>>> prnt(formatter.input_digit("2"))
4142
(650) 253-222
42-
>>> print formatter.input_digit("2")
43+
>>> prnt(formatter.input_digit("2"))
4344
(650) 253-2222
4445
>>>
4546
>>> text = "Call me at 510-748-8230 if it's before 9:30, or on 703-4800500 after 10am."
4647
>>> for match in phonenumbers.PhoneNumberMatcher(text, "US"):
47-
... print match
48+
... prnt(match)
4849
...
4950
PhoneNumberMatch [11,23) 510-748-8230
5051
PhoneNumberMatch [51,62) 703-4800500
5152
>>> 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))
5354
...
5455
+15107488230
5556
+17034800500

python/phonenumbers/phonenumberutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import re
3232

3333
from .re_util import fullmatch # Extra regexp function; see README
34-
from .util import UnicodeMixin, u
34+
from .util import UnicodeMixin, u, prnt
3535
from .unicode_util import digit as unicode_digit
3636

3737
# Data class definitions
@@ -48,7 +48,7 @@
4848
import os
4949
import sys
5050
if os.path.basename(sys.argv[0]) == "buildmetadatafromxml.py":
51-
print >> sys.stderr, "Failed to import generated data (but OK as during autogeneration)"
51+
prnt("Failed to import generated data (but OK as during autogeneration)", file=sys.stderr)
5252
_COUNTRY_CODE_TO_REGION_CODE = {1: ("US",)}
5353
else:
5454
raise

0 commit comments

Comments
 (0)