Search code examples
pythonclassmemorynew-operator

Python Create New Class in Memory


I have Class named "Packet". My Class on github: Github Packet.py Using like this;

from Packet import Packet
paket = Packet(0x5)
paket << "123"

paket2 = Packet(255)
print(paket.storage)
print(paket2.storage)
sys.exit(0)

Result:

bytearray(b'\xff')
bytearray(b'\xff')

but as you see in Result, "paket" variable data should be a bytearray(b'\x05') but it's the same as "paket2" variable. Like in a C, How can I create a class in memory so it doesn't affect the changed value to other classes? Thanks.


Solution

  • Thanks Paul M.

    Answer:

    def __init__(self)
        self.storage = bytearray()