我已经在 stackoverflow 中完成了类似的问题,但找不到与我的问题相近的答案。在最后一行之前的第 3 行下面的代码中给出错误 -
NameError: name '_name_' is not defined
我从大学实验室指南指令中复制了以下代码。不太确定,代码是如何工作的。我们只是被告知为这个实验室复制和粘贴并查看结果。但是,我们必须在命令行中输入所有代码,我被卡住了。如何在代码中修复此错误?
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
class SingleSwitchTopo(Topo):
“Single switch connected to n hosts.”
def_init_(self,n=2,**opts):
#initialize topology and default options
Topo._init_(self,**opts)
switch=self.addSwitch(‘s1’)
#Python’s range(N) generates 0..N-1
for h in range(n):
host=self.addHost(‘h%s’%(h+1))
self.addLink(host,switch)
def simpleTest():
“Create and test a simple network”
topo=SingleSwitchTopo(n=4)
net=Mininet(topo)
net.start
print “Dumping host connections”
dumpNodeConnections(net.hosts)
print “Testing network connectivity”
net.pingAll()
net.stop()
if _name_==’_main_’:
#Tell mininet to print useful information
setLogLevel(‘info’)
simpleTest()