1

How can I prevent the creation of shared memory between multiple instances of a class?

Or, how can I prevent the following?

mwe.py

#!/usr/bin/python3

class Entry:
  content = []

sample = {
    'C1':  Entry(),
    'C2':  Entry(),
    }

sample['C1'].content.append('test')

print(sample['C2'].content)
$ ./mwe.py 
['test']
Suuuehgi
  • 4,547
  • 3
  • 27
  • 32

0 Answers0