<p>我在stackoverflow中也遇到过类似的问题,但找不到接近我问题的答案。在最后一行给出错误之前的3行下面的代码中-</p>
<blockquote>
<p><code>NameError: name '_name_' is not defined</code></p>
</blockquote>
<p>我从大学实验室指南中抄了下面的代码。不太确定,代码是如何工作的。我们只是被告知为这个实验室复制和粘贴并查看结果。但是,我们必须在命令行中输入所有的代码,我被卡住了。如何修复代码中的此错误?</p>
<pre><code>#!/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()
</code></pre>