Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...setattr__: sometimes attributes are not stored in self.__dict__ (for example when using __slots__ or properties, or when using a built-in base class). The same pattern as for __getattribute__ applies, where you call the base class __setattr__ to do the actual work. Here's an example: class C(object): def __setattr__(self, name, value): if hasattr(self, name): raise AttributeError, "attributes are write-once" object.__setattr__(se...
...setattr__: sometimes attributes are not stored in self.__dict__ (for example when using __slots__ or properties, or when using a built-in base class). The same pattern as for __getattribute__ applies, where you call the base class __setattr__ to do the actual work. Here's an example: class C(object): def __setattr__(self, name, value): if hasattr(self, name): raise AttributeError, "attributes are write-once" object.__setattr__(self, name, value) ...
...setattr(toclass, x, fromdict[x]) Listing 3 # The tricky part -- initializing objects from the configuration global # `Configuration' is the top level of the object tree we're going # to mung Configuration = Controls() copy_instance(Configuration, configuration) Configuration.servers = []; for server in configuration[`servers']: Newsite = Server() copy_instance(Newsite, server) Configuration.servers.append(Newsite) Newsite.users = []; for user in server['users']: Ne...
...setattr() now also accept Unicode objects for the attribute name, which are converted to strings using the default encoding before lookup. Multiplication on string and Unicode now does proper bounds checking; e.g. 'a' * 65536 * 65536 will raise ValueError, "repeated string is too long." Better error message when continue is found in try statement in a loop. Standard library and extensions array: reverse() method of array now works. buffer_info() now does ...
If you didn't find what you need, try your search in the Python language documentation.