Permalink
Browse files

Use prnt() for Python 2/3 print compatibility

  • Loading branch information...
1 parent c15fd9c commit d32f784cb4f3ef73ba33ab304404c24d51a9dd08 @daviddrysdale committed Nov 26, 2011
Showing with 17 additions and 16 deletions.
  1. +15 −14 python/phonenumbers/__init__.py
  2. +2 −2 python/phonenumbers/phonenumberutil.py
@@ -3,8 +3,9 @@
Examples of use:
>>> import phonenumbers
+>>> from phonenumbers.util import prnt # equivalent to Py3k print()
>>> x = phonenumbers.parse("+442083661177", None)
->>> print x
+>>> prnt(x)
Country Code: 44 National Number: 2083661177 Leading Zero: False
>>> type(x)
<class 'phonenumbers.phonenumber.PhoneNumber'>
@@ -15,41 +16,41 @@
>>> str(phonenumbers.format_number(x, phonenumbers.PhoneNumberFormat.E164))
'+442083661177'
>>> y = phonenumbers.parse("020 8366 1177", "GB")
->>> print y
+>>> prnt(y)
Country Code: 44 National Number: 2083661177 Leading Zero: False
>>> x == y
True
>>>
>>> formatter = phonenumbers.AsYouTypeFormatter("US")
->>> print formatter.input_digit("6")
+>>> prnt(formatter.input_digit("6"))
6
->>> print formatter.input_digit("5")
+>>> prnt(formatter.input_digit("5"))
65
->>> print formatter.input_digit("0")
+>>> prnt(formatter.input_digit("0"))
650
->>> print formatter.input_digit("2")
+>>> prnt(formatter.input_digit("2"))
650-2
->>> print formatter.input_digit("5")
+>>> prnt(formatter.input_digit("5"))
650-25
->>> print formatter.input_digit("3")
+>>> prnt(formatter.input_digit("3"))
650-253
->>> print formatter.input_digit("2")
+>>> prnt(formatter.input_digit("2"))
650-2532
->>> print formatter.input_digit("2")
+>>> prnt(formatter.input_digit("2"))
(650) 253-22
->>> print formatter.input_digit("2")
+>>> prnt(formatter.input_digit("2"))
(650) 253-222
->>> print formatter.input_digit("2")
+>>> prnt(formatter.input_digit("2"))
(650) 253-2222
>>>
>>> text = "Call me at 510-748-8230 if it's before 9:30, or on 703-4800500 after 10am."
>>> for match in phonenumbers.PhoneNumberMatcher(text, "US"):
-... print match
+... prnt(match)
...
PhoneNumberMatch [11,23) 510-748-8230
PhoneNumberMatch [51,62) 703-4800500
>>> for match in phonenumbers.PhoneNumberMatcher(text, "US"):
-... print phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164)
+... prnt(phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164))
...
+15107488230
+17034800500
@@ -31,7 +31,7 @@
import re
from .re_util import fullmatch # Extra regexp function; see README
-from .util import UnicodeMixin, u
+from .util import UnicodeMixin, u, prnt
from .unicode_util import digit as unicode_digit
# Data class definitions
@@ -48,7 +48,7 @@
import os
import sys
if os.path.basename(sys.argv[0]) == "buildmetadatafromxml.py":
- print >> sys.stderr, "Failed to import generated data (but OK as during autogeneration)"
+ prnt("Failed to import generated data (but OK as during autogeneration)", file=sys.stderr)
_COUNTRY_CODE_TO_REGION_CODE = {1: ("US",)}
else:
raise

0 comments on commit d32f784

Please sign in to comment.