Can I have a class with property named "from"

zljubisic at gmail.com zljubisic at gmail.com
Fri Jun 5 17:36:38 EDT 2020


Hi,

if I define class like this one:

class abc:

    def __init__(self):
        self._from = None

    @property
    def from(self):
        return self._from

    @from.setter
    def from(self, value):
        self._from = value


I get the error SyntaxError: invalid syntax because of the property named from.
Looks like in python from is a keyword that cannot be used as a property name.

I have to create a python object from a complex (nested) json object that has many keys with name "from" and value of date in string format.

As I would like to keep property names as they are in the json file... is there a workaround?

Regards.


More information about the Python-list mailing list