graphnn icon indicating copy to clipboard operation
graphnn copied to clipboard

"arr[:] = args" issue in main.py

Open goodjs1 opened this issue 5 years ago • 2 comments

Hello, I ran the following code in s2v_mvc and got the error. Is it because the version of python? i am using python 3.5 How to fix it? Thanks.

graph_comb/code/s2v_mvc$ ./run_nstep_dqn.sh Traceback (most recent call last): File "main.py", line 78, in api = MvcLib(sys.argv) File "/graph_comb/code/s2v_mvc/mvc_lib/mvc_lib.py", line 18, in init arr[:] = args TypeError: bytes or integer address expected instead of str instance

goodjs1 avatar Sep 01 '19 08:09 goodjs1

Hi, the code is written under python 2.7, so probably you want to have another py2 environment to run it.

Hanjun-Dai avatar Sep 01 '19 15:09 Hanjun-Dai

增加一行代码“ args = [arg.encode('utf-8') for arg in args]”就可以。
def init(self, args): dir_path = os.path.dirname(os.path.realpath(file))
self.lib = ctypes.CDLL('%s/build/dll/libsetcover.so' % dir_path)

    self.lib.Fit.restype = ctypes.c_double
    self.lib.Test.restype = ctypes.c_double
    self.lib.GetSol.restype = ctypes.c_double

    # Convert args to byte strings
    args = [arg.encode('utf-8') for arg in args]
    arr = (ctypes.c_char_p * len(args))()
    arr[:] = args
    self.lib.Init(len(args), arr)
    
    self.ngraph_train = 0
    self.ngraph_test = 0

YixuanLeeee avatar Jun 04 '24 08:06 YixuanLeeee