From 661b25ba288a4fbd11bd86bf7cab182e60f52b5d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 29 Mar 2012 23:36:34 -0400 Subject: [PATCH] Increase Python 3 compatibility (`print()` and `except ... as ...`). --- h5config/config.py | 8 ++++---- h5config/storage/hdf5.py | 6 +++--- h5config/storage/yaml.py | 2 +- h5config/test.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/h5config/config.py b/h5config/config.py index 478ac3f..09037dd 100644 --- a/h5config/config.py +++ b/h5config/config.py @@ -167,8 +167,8 @@ class FloatSetting (NumericSetting): 8.0 >>> try: ... s.convert_from_text('invalid') - ... except ValueError, e: - ... print 'caught a ValueError' + ... except ValueError as e: + ... print('caught a ValueError') caught a ValueError """ def __init__(self, default=1.0, **kwargs): @@ -333,11 +333,11 @@ class Config (dict): ... default=2), ... ] >>> c = MyConfig() - >>> print c.dump() + >>> print(c.dump()) number: one odd: yes guesses: 2 - >>> print c.dump(help=True) # doctest: +NORMALIZE_WHITESPACE + >>> print(c.dump(help=True)) # doctest: +NORMALIZE_WHITESPACE number: one (I have a number behind my back... Default: one. Choices: one, two) odd: yes (The number behind my back is odd. Default: yes. diff --git a/h5config/storage/hdf5.py b/h5config/storage/hdf5.py index 6af6b2d..79e9682 100644 --- a/h5config/storage/hdf5.py +++ b/h5config/storage/hdf5.py @@ -30,14 +30,14 @@ from . import FileStorage as _FileStorage def pprint_HDF5(*args, **kwargs): - print pformat_HDF5(*args, **kwargs) + print(pformat_HDF5(*args, **kwargs)) def pformat_HDF5(filename, group='/'): try: with _h5py.File(filename, 'r') as f: cwg = f[group] ret = '\n'.join(_pformat_hdf5(cwg)) - except IOError, e: + except IOError as e: if 'unable to open' in e.message: if _os_path.getsize(filename) == 0: return 'EMPTY' @@ -204,7 +204,7 @@ class HDF5_Storage (_FileStorage): else: try: v = group[s.name][...] - except Exception, e: + except Exception as e: _LOG.error('Could not access {}/{}: {}'.format( group.name, s.name, e)) raise diff --git a/h5config/storage/yaml.py b/h5config/storage/yaml.py index 7999d20..9b61c6e 100644 --- a/h5config/storage/yaml.py +++ b/h5config/storage/yaml.py @@ -61,7 +61,7 @@ class YAML_Storage (_FileStorage): >>> c['alive'] = True >>> c.save() - >>> print open(filename, 'r').read() # doctest: +REPORT_UDIFF + >>> print(open(filename, 'r').read()) # doctest: +REPORT_UDIFF age: 1.3 alive: yes bids: diff --git a/h5config/test.py b/h5config/test.py index 7da3af4..ac22c10 100644 --- a/h5config/test.py +++ b/h5config/test.py @@ -66,7 +66,7 @@ Saving fills in all the config values. If you want more details, you can dump with help strings. ->>> print c.dump(help=True) # doctest: +REPORT_UDIFF, +NORMALIZE_WHITESPACE +>>> print(c.dump(help=True)) # doctest: +REPORT_UDIFF, +NORMALIZE_WHITESPACE name: (The parrot's name. Default: .) species: Norwegian Blue (Type of parrot. Default: Norwegian Blue. Choices: Norwegian Blue, Macaw) -- 2.26.2