我尝试使用Berkeley Simulations Lab提供的Python27块连接Modelica和Python:
http://simulationresearch.lbl.gov/modelica
我使用这个块来调用Python函数:
def Test2(WriteValues):
''' Connection Test - Works if started from Dymola
'''
#Doing nothing and returning the input
ReturnList=WriteValues
return (ReturnList)
工作完美。在
现在我需要导入一些模块
^{pr2}$同样有效
现在我只想导入一个模块,它不是Python的一部分,而是一个站点包:
def Test1(WriteValues):
'''Connection Test - Doesnt work if started from Dymola
'''
#Importing some Bacpypes Module
#Path is by default C:\Python27\Lib\site-packages\BACpypes-0.7-py2.7.egg\bacpypes
#My os is win7
from bacpypes.core import run
#Doing nothing and returning the input
ReturnList=WriteValues
return (ReturnList)
这不起作用。不管我是在函数内部还是全局导入BACpypes模块-错误总是
'module' object has no attribute 'argv'
同事们向我指出,这可能与多重进口问题有关。Modelica每10秒调用一次函数(实时模拟)。在
如果我在Modelica之外调用函数Test1,就没有问题了。它只会在使用Python27块时失败!在
有人知道如何让BACpypes导入工作吗?在
更新2013-10-16:
我打印出了系统argv对于Python目录中的脚本执行和Modelica的执行。在
在系统argv从Python目录:
['C:\\Python27\\Testcon.py']
在系统argv如果从Modelica内部调用函数:
['modpython']
这可能与我收到的错误消息有关吗?在
导致该错误的原因是
bacpypes
使用了sys.argv
,但是Python解释器没有调用PySys_SetArgv
。在这将在Modelica Buildings库的下一个版本中修复,请参见https://github.com/lbl-srg/modelica-buildings/issues/191
相关问题 更多 >
编程相关推荐