简体   繁体   English

(Python,Gurobi)TypeError:预期的字符串或Unicode对象,找到列表

[英](Python, Gurobi) TypeError: expected string or Unicode object, list found

I'm using Gurobi from Python. 我正在使用Python的Gurobi。 For this segment of code: 对于这段代码:

    Xlij = {}       
    for i in self.init.getNodes() - self.init.getActiveNodes(): 
        for l in self.init.getL():
            for j in self.init.getNeighbors(i, l):
                Xlij[l,i,j] = model.addVar(vtype=GRB.BINARY, name=["X"+str((l,i,j))])

I'm getting this error: 我收到此错误:

File "C:\Python27\My sim\Solutiongrb.py", line 34, in run
vars[l,i,j] = model.addVar(vtype=GRB.BINARY, name=["X"+str((l,i,j))])
File "model.pxi", line 2038, in gurobipy.Model.addVar (../../src/python/gurobipy.c:63880)
TypeError: expected string or Unicode object, list found

Although the same syntax isused in Gurobi examples document page 475. Any explanation? 尽管在Gurobi示例文档第475页中使用了相同的语法。有什么解释吗? Thanks! 谢谢!

["X"+str((l,i,j))]

is a list with one string element. 是带有一个字符串元素的列表。 Probably you want just "X"+str((l,i,j)) 可能您只需要"X"+str((l,i,j))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python多处理:TypeError:期望的字符串或Unicode对象,找到NoneType - Python multiprocessing: TypeError: expected string or Unicode object, NoneType found / image /预期的字符串或Unicode对象处出现TypeError,发现InMemoryUploadedFile - TypeError at /image/ expected string or Unicode object, InMemoryUploadedFile found PyQt / TypeError:预期的字符串或Unicode对象,找到了QString` - PyQt/TypeError: expected string or Unicode object, QString found` DictReader 错误:预期的字符串或 Unicode 对象,找到列表 - DictReader error: expected string or Unicode object, list found Python错误“ TypeError:强制转换为Unicode:需要字符串或缓冲区,找到列表” - Python Error“TypeError: coercing to Unicode: need string or buffer, list found” python 2.6 TypeError:强制转换为Unicode:需要字符串或缓冲区,找到列表 - python 2.6 TypeError: coercing to Unicode: need string or buffer, list found python gensim TypeError:强制转换为Unicode:需要字符串或缓冲区,找到列表 - python gensim TypeError: coercing to Unicode: need string or buffer, list found Python脚本TypeError:强制转换为Unicode:需要字符串或缓冲区,找到列表 - Python Script TypeError: coercing to Unicode: need string or buffer, list found mod_wsgi:TypeError:标头名称的预期字节字符串对象,找到unicode类型的值 - mod_wsgi: TypeError: expected byte string object for header name, value of type unicode found 尝试在python 2.7 TypeError中删除Unicode特殊字符时出错:预期为字符串或其他字符缓冲区对象 - Error while try to remove Unicode special character in python 2.7 TypeError: expected a string or other character buffer object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM