[fix] Linux bytes to string
@@ -73,8 +73,15 @@ def _filename(simpath, name, frame):
return join(simpath, "%s_%06i.npz" % (name, frame))
+def _str(bytes_or_str): # on Linux, os.listdir returns bytes instead of strings
+ if isinstance(bytes_or_str, str):
+ return bytes_or_str
+ else:
+ return str(bytes_or_str, 'utf-8')
+
+
def get_fieldnames(simpath) -> tuple:
- fieldnames_set = {str(f)[:-11] for f in os.listdir(simpath) if str(f).endswith(".npz")}
+ fieldnames_set = {_str(f)[:-11] for f in os.listdir(simpath) if _str(f).endswith(".npz")}
return tuple(sorted(fieldnames_set))
@@ -84,7 +91,7 @@ def first_frame(simpath, fieldname=None):
def get_frames(simpath, fieldname=None, mode="intersect"):
if fieldname is not None:
- all_frames = {int(f[-10:-4]) for f in os.listdir(simpath) if str(f).startswith(fieldname) and str(f).endswith(".npz")}
+ all_frames = {int(f[-10:-4]) for f in os.listdir(simpath) if _str(f).startswith(fieldname) and _str(f).endswith(".npz")}
return tuple(sorted(all_frames))
else:
frames_sets = [set(get_frames(simpath, fieldname)) for fieldname in get_fieldnames(simpath)]
