summaryrefslogtreecommitdiff
path: root/example/closurecalc/calc.py
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2008-11-27 19:36:14 +0000
committerDavid Beazley <dave@dabeaz.com>2008-11-27 19:36:14 +0000
commitca5170e19a22acc8c960c1e2d60ecf353a197057 (patch)
tree3d18cafc75d61f3bc5412338db061175e796a212 /example/closurecalc/calc.py
parentc66982f8e7dc7de7bbb73c1e40699fd22aef5eac (diff)
downloadply-ca5170e19a22acc8c960c1e2d60ecf353a197057.tar.gz
Python 2.6/3.0 compatibility changes
Diffstat (limited to 'example/closurecalc/calc.py')
-rw-r--r--example/closurecalc/calc.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/example/closurecalc/calc.py b/example/closurecalc/calc.py
index 7f4bf4f..a1d5845 100644
--- a/example/closurecalc/calc.py
+++ b/example/closurecalc/calc.py
@@ -9,6 +9,9 @@
import sys
sys.path.insert(0,"../..")
+if sys.version_info[0] >= 3:
+ raw_input = input
+
# Make a calculator function
def make_calculator():
@@ -36,7 +39,7 @@ def make_calculator():
try:
t.value = int(t.value)
except ValueError:
- print "Integer value too large", t.value
+ print("Integer value too large %s" % t.value)
t.value = 0
return t
@@ -45,7 +48,7 @@ def make_calculator():
t.lexer.lineno += t.value.count("\n")
def t_error(t):
- print "Illegal character '%s'" % t.value[0]
+ print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
# Build the lexer
@@ -95,14 +98,14 @@ def make_calculator():
try:
p[0] = variables[p[1]]
except LookupError:
- print "Undefined name '%s'" % p[1]
+ print("Undefined name '%s'" % p[1])
p[0] = 0
def p_error(p):
if p:
- print "Syntax error at '%s'" % p.value
+ print("Syntax error at '%s'" % p.value)
else:
- print "Syntax error at EOF"
+ print("Syntax error at EOF")
# Build the parser
@@ -126,6 +129,6 @@ while True:
break
r = calc(s)
if r:
- print r
+ print(r)