私はC言語のように、Pythonで構造体を作成したいと思います。私はこれのためにnamedtuple()を使用しようとしました。しかし、私はカスタム構造内で記述した変数の値を更新することはできません。namedtuple()構造体内の変数の値を更新する
from collections import namedtuple as nt
Struct = nt('Struct','all left right bottom top near far')
そして、これは私がこの方法でやろうとしていますものです::
class codeClip:
def compOutCode(x,y,z,xmin,xmax,ymin,ymax,zmin,zmax):
code = Struct(0,0,0,0,0,0,0)
if(y > ymax):
code.top = 1
code.all += code.top
elif(y < ymin):
code.bottom = 1
return code
それがこのエラーを与えているしかし:
code.top = 1 AttributeError: can't set attribute
何ここ は、私はそれを宣言した方法です私はする必要がありますか? Pardon私、私はかなりPythonで新しく、まだこれらのすべてに慣れています。
可能な重複[namedtuplesのリストの値を変更](http://stackoverflow.com/questions/31252939/changing-values-of-a-list-of-namedtuples) – AKS