Skip to content
Snippets Groups Projects
Commit be75350b authored by Thomas Uram's avatar Thomas Uram
Browse files

Make genericio.py Python2/3-agnostic

parent 5e1952a8
No related branches found
Tags 20170925
No related merge requests found
...@@ -37,9 +37,10 @@ ...@@ -37,9 +37,10 @@
# #
# ***************************************************************************** # *****************************************************************************
from __future__ import print_function
import numpy as np import numpy as np
import ctypes as ct import ctypes as ct
import os import os,sys
#Define where the library is and load it #Define where the library is and load it
_path = os.path.dirname(__file__) _path = os.path.dirname(__file__)
...@@ -71,14 +72,17 @@ libpygio.inspect_gio.restype=None ...@@ -71,14 +72,17 @@ libpygio.inspect_gio.restype=None
libpygio.inspect_gio.argtypes=[ct.c_char_p] libpygio.inspect_gio.argtypes=[ct.c_char_p]
def gio_read(file_name,var_name): def gio_read(file_name,var_name):
if sys.version_info[0] == 3:
file_name = bytes(file_name,'ascii')
var_name = bytes(var_name,'ascii')
var_size = libpygio.get_elem_num(file_name) var_size = libpygio.get_elem_num(file_name)
var_type = libpygio.get_variable_type(file_name,var_name) var_type = libpygio.get_variable_type(file_name,var_name)
field_count = libpygio.get_variable_field_count(file_name,var_name) field_count = libpygio.get_variable_field_count(file_name,var_name)
if(var_type==10): if(var_type==10):
print "Variable not found" print("Variable not found")
return return
elif(var_type==9): elif(var_type==9):
print "variable type not known (not int32/int64/float/double)" print("variable type not known (not int32/int64/float/double)")
elif(var_type==0): elif(var_type==0):
#float #float
result = np.ndarray((var_size,field_count),dtype=np.float32) result = np.ndarray((var_size,field_count),dtype=np.float32)
...@@ -101,10 +105,15 @@ def gio_read(file_name,var_name): ...@@ -101,10 +105,15 @@ def gio_read(file_name,var_name):
return result return result
def gio_has_variable(file_name,var_name): def gio_has_variable(file_name,var_name):
if sys.version_info[0] == 3:
file_name=bytes(file_name,'ascii')
var_name=bytes(var_name,'ascii')
var_size = libpygio.get_elem_num(file_name) var_size = libpygio.get_elem_num(file_name)
var_type = libpygio.get_variable_type(file_name,var_name) var_type = libpygio.get_variable_type(file_name,var_name)
return var_type!=10 return var_type!=10
def gio_inspect(file_name): def gio_inspect(file_name):
if sys.version_info[0] == 3:
file_name=bytes(file_name,'ascii')
libpygio.inspect_gio(file_name) libpygio.inspect_gio(file_name)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment