这是我的代码
N = namedtuple("N", ['ind', 'set', 'v'])
def solve()
items=[]
stack=[]
R = set(range(0,8))
for i in range(0,8):
items.append(N(i,R,8))
stack.append(N(0,R-set(range(0,1)),i))
while(len(stack)>0):
node = stack.pop()
print node
print items[node.ind]
items[node.ind].v = node.v
Run Code Online (Sandbox Code Playgroud)
在最后一行,我不能将items[node.ind].v
值设置node.v
为我想要的,并得到错误
"AttributeError: can't set attribute"
Run Code Online (Sandbox Code Playgroud)
我不知道什么是错的,但它必须是基于语法的东西,因为使用语句node.v+=1
也会显示相同的错误.我是Python的新手,所以请建议一种方法来实现上述变更.
我看了
如果您正在使用多播委托,您应该知道将被调用链接到同一委托的方法的顺序是正式未定义的.因此,您应该避免编写依赖于以任何特定顺序调用此类方法的代码.
但是当我尝试使用这段代码时
using System;
namespace Wrox.ProCSharp.Delegates
{
class Program
{
static void One()
{
Console.WriteLine("watch when i occur");
throw new Exception("Error in watching");
}
static void Two()
{
Console.WriteLine("count");
}
static void Three()
{
Console.WriteLine("great");
}
static void Main()
{
Action d1 = Two;
d1+=Two;
d1+=Two;
d1+=Two;
d1+=One;
d1+=Three;
d1+=Three;
d1+=Three;
Delegate[] delegates = d1.GetInvocationList();
foreach (Action d in delegates)
try
{
d1();
}
catch(Exception)
{
Console.WriteLine("Exception Caught");
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出
count
count
count
count
watch when …
Run Code Online (Sandbox Code Playgroud)