0

I am new to Python.

There is another question, Are static class variables possible?, that has answered how to use static variables in Python. But it will be different when serializing a class using cloudpickle.

Because cloudpickle will serialize the whole class, including static variables, and restore when loaded. That makes two classes with the same name exist.

Does Python have things like classloader in Java, that can make sure only one class instance exists in the whole context?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Xilang
  • 1,513
  • 3
  • 18
  • 36
  • In python every variable declared in class are considered as "static variable". `class Foo: x = 1` – gachdavit May 25 '19 at 14:01
  • No, *[Python](http://en.wikipedia.org/wiki/Python_%28programming_language%29)*. – Peter Mortensen May 25 '19 at 14:03
  • Generally all attributes of classes, modules and packages and global variables are static, but be aware of the differences when replacing the reference or changing the referenced object. – Klaus D. May 25 '19 at 14:12

0 Answers0