summaryrefslogtreecommitdiff
path: root/examples/sparser.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-10-24 20:11:14 -0700
committerPaul McGuire <ptmcg@users.noreply.github.com>2019-10-24 22:11:14 -0500
commitf73e2571fb643a2afdde365eeee0fe0f3f4f5300 (patch)
treef9015586cee7efc5e60eee78a8ebcbaa4e9e953d /examples/sparser.py
parent696808023f10207461d7b22dc1d02cbed44e2bfa (diff)
downloadpyparsing-git-f73e2571fb643a2afdde365eeee0fe0f3f4f5300.tar.gz
Use pyupgrade to upgrade the code to use Python3 conventions (#138)
The pyupgrade project is available at https://github.com/asottile/pyupgrade and can be installed through pip. The pyupgrade tool automatically upgrades syntax for newer versions of the language. As pyparsing is now Python 3 only, can apply some cleanups and simplifications. Ran the tool using the following command: $ find . -name \*.py -exec pyupgrade --py3-plus {} \; For now, pyparsing.py was skipped while it is refactored to a package.
Diffstat (limited to 'examples/sparser.py')
-rw-r--r--examples/sparser.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/sparser.py b/examples/sparser.py
index d4604da..39758d6 100644
--- a/examples/sparser.py
+++ b/examples/sparser.py
@@ -77,12 +77,12 @@ def msg(txt):
def debug(ftn, txt):
"""Used for debugging."""
if debug_p:
- sys.stdout.write("{0}.{1}:{2}\n".format(modname, ftn, txt))
+ sys.stdout.write("{}.{}:{}\n".format(modname, ftn, txt))
sys.stdout.flush()
def fatal(ftn, txt):
"""If can't continue."""
- msg = "{0}.{1}:FATAL:{2}\n".format(modname, ftn, txt)
+ msg = "{}.{}:FATAL:{}\n".format(modname, ftn, txt)
raise SystemExit(msg)
def usage():
@@ -138,18 +138,18 @@ class ParseFileLineByLine:
definition file is available __init__ will then create some pyparsing
helper variables. """
if mode not in ['r', 'w', 'a']:
- raise IOError(0, 'Illegal mode: ' + repr(mode))
+ raise OSError(0, 'Illegal mode: ' + repr(mode))
if string.find(filename, ':/') > 1: # URL
if mode == 'w':
- raise IOError("can't write to a URL")
+ raise OSError("can't write to a URL")
import urllib.request, urllib.parse, urllib.error
self.file = urllib.request.urlopen(filename)
else:
filename = os.path.expanduser(filename)
if mode == 'r' or mode == 'a':
if not os.path.exists(filename):
- raise IOError(2, 'No such file or directory: ' + filename)
+ raise OSError(2, 'No such file or directory: ' + filename)
filen, file_extension = os.path.splitext(filename)
command_dict = {
('.Z', 'r'):