【发布时间】:2019-03-02 13:17:08
【问题描述】:
我有文件 mikrotik.py
'ip route add dst-address={}/{} gateway={}'.format(destination,prefix,gateway)
还有一些代码
import os
localfilepath = os.getcwd()
staticDir = localfilepath+"/website/plugin/config/routing/static/"
vendors = staticDir+"MIKROTIK.py"
destination = 192.168.2.0
prefix = 24
gateway = 192.168.1.1
x = execfile(vendors)
print x
结果是
None
我想要的结果是
ip route add dst-address=192.168.2.0/24 gateway=192.168.1.1
当我使用时
x = open(vendors)
print x
结果是
'ip route add dst-address={}/{} gateway={}'.format(destination,prefix,gateway)
提前致谢
所以最后我使用了 eval(x)
结果是 ip route add dst-address=192.168.2.0/24 gateway=192.168.1.1,我不知道这是不是最好的方法
【问题讨论】:
标签: python networking execfile