diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2012-11-23 08:54:10 +0000 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2012-11-23 08:54:10 +0000 |
commit | 774e46526945ea91265734a2dc82d15eed515577 (patch) | |
tree | 734ae210c20a98f01fe029f7e6eeb7a93b4617fb /src/examples/SimpleCalc.py | |
parent | 6b12041d4656f4cda910f24acda8d71013166fbd (diff) | |
download | pyparsing-git-774e46526945ea91265734a2dc82d15eed515577.tar.gz |
Clean up examples to be Python 3 compatible
Diffstat (limited to 'src/examples/SimpleCalc.py')
-rw-r--r-- | src/examples/SimpleCalc.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/examples/SimpleCalc.py b/src/examples/SimpleCalc.py index 577c8e3..46a5dff 100644 --- a/src/examples/SimpleCalc.py +++ b/src/examples/SimpleCalc.py @@ -22,7 +22,7 @@ #
#
-from __future__ import division
+
# Uncomment the line below for readline support on interactive terminal
# import readline
@@ -66,13 +66,13 @@ if __name__ == '__main__': input_string=''
# Display instructions on how to quit the program
- print "Type in the string to be parsed or 'quit' to exit the program"
- input_string = raw_input("> ")
+ print("Type in the string to be parsed or 'quit' to exit the program")
+ input_string = input("> ")
while input_string != 'quit':
if input_string.lower() == 'debug':
debug_flag=True
- input_string = raw_input("> ")
+ input_string = input("> ")
continue
# Reset to an empty exprStack
@@ -82,37 +82,37 @@ if __name__ == '__main__': # try parsing the input string
try:
L=pattern.parseString( input_string, parseAll=True )
- except ParseException,err:
+ except ParseException as err:
L=['Parse Failure',input_string]
# show result of parsing the input string
- if debug_flag: print input_string, "->", L
+ if debug_flag: print(input_string, "->", L)
if len(L)==0 or L[0] != 'Parse Failure':
- if debug_flag: print "exprStack=", exprStack
+ if debug_flag: print("exprStack=", exprStack)
# calculate result , store a copy in ans , display the result to user
try:
result=evaluateStack(exprStack)
- except Exception,e:
- print str(e)
+ except Exception as e:
+ print(str(e))
else:
variables['ans']=result
- print result
+ print(result)
# Assign result to a variable if required
if L.varname:
variables[L.varname] = result
- if debug_flag: print "variables=",variables
+ if debug_flag: print("variables=",variables)
else:
- print 'Parse Failure'
- print err.line
- print " "*(err.column-1) + "^"
- print err
+ print('Parse Failure')
+ print(err.line)
+ print(" "*(err.column-1) + "^")
+ print(err)
# obtain new input string
- input_string = raw_input("> ")
+ input_string = input("> ")
# if user type 'quit' then say goodbye
- print "Good bye!"
+ print("Good bye!")
|