Skip to content

Commit

Permalink
python2 to 3 compatbility for integer division and testing for string…
Browse files Browse the repository at this point in the history
… types
  • Loading branch information
ryanslynch authored and scottransom committed Nov 12, 2019
1 parent 0180640 commit 154710b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions bin/pyplotres.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ def get_xdata(self, key):
"""Return label describing xaxis and the corresponding
data given keyword 'key'.
"""
if not (isinstance(key, bytes) or isinstance(key, str)):
# Python2/3 compatible way of checking for string types
# Taken from https://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility
try:
basestring
except NameError:
basestring = str
if not isinstance(key, basestring):
raise ValueError("key must be of type string.")
xopt = key.lower()
if xopt == 'numtoa':
Expand All @@ -228,7 +234,13 @@ def get_ydata(self, key, postfit=True):
'postfit' is a boolean argument that determines if
postfit, or prefit data is to be returned.
"""
if not (isinstance(key, bytes) or isinstance(key, str)):
# Python2/3 compatible way of checking for string types
# Taken from https://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility
try:
basestring
except NameError:
basestring = str
if not isinstance(key, basestring):
raise ValueError("key must be of type string.")
yopt = key.lower()
if postfit:
Expand Down
2 changes: 1 addition & 1 deletion lib/python/residuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def read_residuals(filename="resid2.tmp"):
not (reclen==struct.calcsize(rectype))):
print("Warning: possibly reading residuals incorrectly... don't understand record size")
infile.seek(0, 0) # position at file start
r.numTOAs = int(filelen / reclen)
r.numTOAs = filelen // reclen
r.bary_TOA = Num.zeros(r.numTOAs, 'd')
r.postfit_phs = Num.zeros(r.numTOAs, 'd')
r.postfit_sec = Num.zeros(r.numTOAs, 'd')
Expand Down

0 comments on commit 154710b

Please sign in to comment.