Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
1 vote
1 answer
89 views

I was going through classes doc. And I found the following paragraph. Notice that code passed to exec() or eval() does not consider the classname of the invoking class to be the current class; this ...
0 votes
1 answer
63 views

I'm having trouble applying a decorator to an imported function. Suppose I have the following foo.py module: # contents of foo.py def bar(): return "hello" I now want to import bar from ...
1 vote
1 answer
248 views

If I want to add a value to a field in a protocol buffer that isn't known at compile time, I'm currently doing setattr. I normally don't like using setattr because it seems less secure. But when I ...
1 vote
1 answer
58 views

I was trying to create a dataclass with shorter aliases for longer fields. Since I wanted to be able to add new fields (with long and short names) without having to write a @property decorated "...
0 votes
0 answers
103 views

I'm writing a mod for a Ren'Py game that includes possibility to edit game's variables' values ("cheating"). Variables in the game include different ones from simple booleans to pretty ...
Margo's user avatar
  • 21
-3 votes
1 answer
44 views

class D: def __init__(self): self._attr = 1 self._attr2 = 2 def __getattr__(self, name): if name == 'data': return (self._attr, self._attr2) def ...
1 vote
2 answers
88 views

I though that for python object obj() is equivalent to obj.__call__(). But it looks like it doesn't hold when setattr was used. In [46]: class A: ...: def __call__(self): ...: ...
0 votes
0 answers
180 views

I'm trying to associate additional data with a Python list. Ideally, I'd like to add custom attributes to a list object, similar to how you'd add attributes to a custom class. For example: a = [1, 2, ...
0 votes
0 answers
27 views

https://docs.python.org/3/library/functions.html#setattr From this documentation, I cannot tell if a deep copy is made or not. I'm working with a codebase currently that uses setattr is a rather ...
3 votes
1 answer
77 views

I'm trying to set attributes to a class of which I don't know the name a-priori. I also want to avoid users to write to that attribute, so I use a property factory with getters and setters which ...
Mezzerine's user avatar
0 votes
0 answers
95 views

I'm trying to setattr() using name list. When calling it the names containing index number in square brackets raises AttributeError in Python 2 and TypeError in Python. class NodeClass(): def __init__(...
IKA's user avatar
  • 161
0 votes
0 answers
103 views

I'm trying to implement a Config class that holds and keeps track of an arbitrary amount of Settings. I'd like to get and set the Settings like c = Config(<CONTAINER_OF_POSSIBLE_SETTINGS>); c.x =...
0 votes
0 answers
89 views

I used super() as a part of the __setattr__ method to update a dictionary whenever an attribute value is set on an instance of a class; however, a warning reported as my class object has no such ...
0 votes
2 answers
139 views

is there a simple way to prevent setting new class attrs? while trying with the following snippet, shouldn't setattr(Derived, "test1", 1) call the __setattr__ from Base? class Base: def ...
deponovo's user avatar
  • 1,442
3 votes
2 answers
827 views

I want in class B to automatically add the decorator _preCheck to all methods that have been inherited from class A. In the example b.double(5) is correctly called with the wrapper. I want to avoid to ...

15 30 50 per page
1
2 3 4 5
...
14

AltStyle によって変換されたページ (->オリジナル) /