Question: Is there any way to translate this Java code into Python?

```
class Foo
{
    final static private List<Thingy> thingies = 
       ImmutableList.of(thing1, thing2, thing3);
}

```

e.g. `thingies` is an immutable private list of `Thingy` objects that belongs to the `Foo` class rather than its instance.

I know how to define static class variables from this question [Static class variables in Python](https://stackoverflow.com/questions/68645/static-class-variables-in-python) but I don't know how to make them immutable and private.

Answer: 
In Python the convention is to use a `_` prefix on attribute names to mean `protected` and a `__` prefix to mean `private`. This isn't enforced by the language; programmers are expected to know not to write code that relies on data that isn't public.

If you really wanted to enforce immutability, you could use a metaclass[[docs](http://docs.python.org/reference/datamodel.html#customizing-class-creation)] (the class of a class). Just modify `__setattr__` and `__delattr__` to raise exceptions when someone attempts to modify it, and make it a `tuple` (an immutable list) [[docs](http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences)].

```
class FooMeta(type):
    """A type whose .thingies attribute can't be modified."""

    def __setattr__(cls, name, value):
        if name == "thingies":
            raise AttributeError("Cannot modify .thingies")
        else:
            return type.__setattr__(cls, name, value)

    def __delattr__(cls, name):
        if name == "thingies":
            raise AttributeError("Cannot delete .thingies")
        else:
            return type.__delattr__(cls, name)

thing1, thing2, thing3 = range(3)

class Foo(object):
    __metaclass__ = FooMeta
    thingies = (thing1, thing2, thing3)
    other = [1, 2, 3]

```

### Examples

```
print Foo.thingies # prints "(0, 1, 2)"
Foo.thingies = (1, 2) # raises an AttributeError
del Foo.thingies # raise an AttributeError

```

```
Foo.other = Foo.other + [4] # no exception
print Foo.other # prints "[1, 2, 3, 4]"

```

It would still technically be possible to modify these by going through the class's internal `.__dict__` of attributes, but this should be enough to deter most users, it's very difficult to entirely secure Python objects.
You can achieve the `final` part using type hints\*. As others have said, `__` achieves the `private` aspect well enough, so

```py
from typing import List
from typing_extensions import Final

class Foo:
    __thingies: Final[List[Thingy]] = ImmutableList.of(thing1, thing2, thing3)

```

I'll leave the definition of `ImmutableList` to you. A `tuple` will probably do.

\*with the usual caveat that users can ignore them