Questions tagged [class-attributes]

170 questions
2
votes
3 answers

In Angular use ng-bind in class

In Angular I can write next : class="{{ DayTypesClasses[request.typeId] }}" which will set css-class according to expression value But I've found that ng-bind can make the same but also save some time for this binding. I've tried to use ng-bind…
demo
  • 6,038
  • 19
  • 75
  • 149
2
votes
2 answers

Reflection and attributes -- removal? modification? OR windows service in full trust?

I want to remove the security permissions from a class I don't have access to the source for. Is it possible to, via reflection, remove or modify the attribute? [...PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust"),…
Joshua Evensen
  • 1,544
  • 1
  • 15
  • 33
2
votes
1 answer

Dictionary class attribute that refers to other class attributes in the definition

While there are numerous ways around this, because of a personality fault I can't let it go until I understand the nature of the failure. Attempting: class OurFavAnimals(object): FAVE = 'THATS ONE OF OUR FAVORITES' NOTFAVE = 'NAH WE DONT…
eriophora
  • 999
  • 1
  • 8
  • 20
2
votes
1 answer

Lazy class property decorator

I have one django model which needs to do some processing referring the custom user model. I can't work with the class of this model at class loading time because the loading order of the classes is unknown. So I need to add some class attributes at…
Adrián
  • 6,135
  • 1
  • 27
  • 49
1
vote
1 answer

Add an attribute to an existing C# class without losing existing extension methods?

I have an existing partial class that has extension methods applied to it, in one project. I want to add an attribute to that class within a different project, but when I create a second partial class the extension methods disappear. Initially I…
Josh Russo
  • 3,080
  • 2
  • 41
  • 62
1
vote
2 answers

How do I access the variable inside a class method from another python file?

I have two python files main.py and conftest.py. I want to access a variable of a method of the class Test declared in main.py from a function declared in conftest.py. I have tried a bit, but I know it's wrong as I get a syntax error in the first…
Libin Thomas
  • 829
  • 9
  • 18
1
vote
1 answer

Is it possible to make a class_attribute private or protected in Rails?

I have a situation where I need a variable (e.g. foo) which is used internally within a class (e.g. Parent) and sub-classes (e.g. Child). In my case, I'm using Single Table Inheritance. Child should inherit the variable foo from Parent if Child does…
1
vote
0 answers

Is it possible to access a class attribute in a python decorator?

Is it possible to access a class attribute in a python decorator? Code: class ButtonView(discord.ui.View): def __init__(self, allPages, author, *, timeout = 180): super().__init__(timeout=timeout) self.allPages = allPages …
1
vote
1 answer

Accessing class attributes in __str__ method in Python

I am making a card class in Python 3.x. I am trying to utilize the __str__ method to print the card. class Card: ranks = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"] …
ImHungry48
  • 13
  • 2
1
vote
2 answers

Python - using metaclass & class attributes in object instances

I have a number of classes that inherit a common one. I need the parent class to keep track of a bunch of dependencies/relationships that are defined at the class level. Something like: class Meta(type): ALLDEPENDENCIES = {} def…
logicOnAbstractions
  • 2,178
  • 4
  • 25
  • 37
1
vote
2 answers

Python - How to get an attribute of a derived class using a method in the base class

Let's say I have a Dog class that inherits from an Animal class. I want every Animal to make a noise of some sort, and I want to be able to access this noise using a method, regardless of whether an instance of the animal exists. This is essentially…
moonybaby
  • 33
  • 3
1
vote
1 answer

why don't closures work within python classes?

class Example: my_list = [1, 2, 3] def __init__(self): self.my_list = my_list example = Example() print(example.my_list) running the above code returns this NameError: name 'my_list' is not defined. class Example: my_list =…
Ser.T
  • 51
  • 4
1
vote
1 answer

Redirecting function definitions in python

Pointing the class method at the instance method is clearly causing problems: class A(dict): def __getitem__(self, name): return dict.__getitem__(self, name) class B(object): def __init__(self): self.a = A() …
Dan
  • 33,953
  • 24
  • 61
  • 87
1
vote
3 answers

Class attribute defined as a length of another List Type class attribute doesn't update itself and always returns the same value

I'm writing a code for the card game 'War'. While defining a "Deck" class, I've defined an attribute "self.cards" which gives the list of all the cards currently in a deck of cards. I've also defined an attribute "self.length" which is expected to…
Yadvender
  • 13
  • 2
1
vote
3 answers

How to solve "Unresolved attribute reference for class"

I have been working on a small project which is a web-crawler template. Im having an issue in pycharm where I am getting a warning Unresolved attribute reference 'domain' for class 'Scraper' from abc import abstractmethod import requests import…
PythonNewbie
  • 1,031
  • 1
  • 15
  • 33