aboutsummaryrefslogtreecommitdiff
path: root/scripts/add-beam-params
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-05-12 15:51:33 +0200
committerThomas White <taw@physics.org>2017-05-12 15:51:33 +0200
commit690666e32643302970b1f54bbaa0efe83aac7e86 (patch)
treecd4e9b32b46160649a1fa4f5c1786b1cbf614356 /scripts/add-beam-params
parent4227f0b190b08ecc50a49875e86dbb9b14714bdd (diff)
Make all Python scripts compatible with Python 2 and 3
It would be nice to upgrade completely to Python 3, but this may create problems at SLAC because psana only supports Python 2 (Python 3 is available, but means that users have to jump through hoops to run a simple CrystFEL script). None of our scripts do anything complicated, so they can all be compatible with both so far. If anyone adds a script which requires a particular version, make sure to specify the version in the first line, consistent with PEP 394.
Diffstat (limited to 'scripts/add-beam-params')
-rwxr-xr-xscripts/add-beam-params14
1 files changed, 7 insertions, 7 deletions
diff --git a/scripts/add-beam-params b/scripts/add-beam-params
index 23c9caaf..e4e38f70 100755
--- a/scripts/add-beam-params
+++ b/scripts/add-beam-params
@@ -1,13 +1,13 @@
#!/usr/bin/env python
-
+# -*- coding: utf-8 -*-
#
# Add beam parameters to stream
#
-# Copyright (c) 2014 Deutsches Elektronen-Synchrotron DESY,
-# a research centre of the Helmholtz Association.
+# Copyright © 2014-2017 Deutsches Elektronen-Synchrotron DESY,
+# a research centre of the Helmholtz Association.
#
# Author:
-# 2014 Thomas White <taw@physics.org>
+# 2014,2017 Thomas White <taw@physics.org>
#
import sys
@@ -66,7 +66,7 @@ def count_crystals(f, g, start_after, stop_after):
in_crystal = 0
need_end_chunk = 1
- print "Wrote %i crystals to %s" % (n_crystals_written, opt.ofn)
+ print("Wrote {} crystals to {}".format(n_crystals_written, opt.ofn))
def count_chunks(f, g, start_after, stop_after):
n_chunks_seen = 0
@@ -95,7 +95,7 @@ def count_chunks(f, g, start_after, stop_after):
if n_chunks_written == stop_after:
break
- print "Wrote %i chunks to %s" % (n_chunks_written, opt.ofn)
+ print("Wrote {} chunks to {}".format(n_chunks_written, opt.ofn))
op = optparse.OptionParser()
op.add_option('', '--input', action='store', type='string', dest='ifn',
@@ -111,7 +111,7 @@ op.add_option('', '--chunks', action='store_true', dest='chunks',
opt,arg = op.parse_args(sys.argv)
if not (opt.ifn and opt.ofn):
- print "You need at least --input and --output"
+ print("You need at least --input and --output")
exit(1)
f = open(opt.ifn, 'r')