I'm working with scapy and have a question related to scapy but also python. I try to use variables as scapy field-names. Here is an extract of code that should illustrate what I try to do (It is not working):
class Test(Packet):
name = "Test23"
def __init__(self,foo=None):
self.foo=foo
fields_desc = [
BitField(self.foo, 0x0, 4),
BitField("bar", 0x3, 4)
]
Now I imagine the problem is due to the fact that fields_desc is a class attribute and not a class variable. Now, how could I reach what I want? (setting the name of self.foo at runtime/class inizialisation?)
I would be thankfull for any help. With best regards
Edit: Appending an counter would be enough. I tried:
class Counter:
count = 0
def __init__(self):
self.__class__.count += 1
foo = [
"lala"+str(count)
]
print foo
a=Counter()
a.count
print a.foo
b=Counter()
b.count
print b.foo
But doesn't seem to work. Would be cool if you could point me to the correct direction, somehow I'm lost.