Questions tagged [attributes]

The attributes tag should be used for any issues relating to a property of an object, element, or file, etc.

In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such.

For clarity, attributes should more correctly be considered metadata. An attribute is frequently and generally a property of a property.

However, in actual usage, the term attribute can and is often treated as equivalent to a property, depending on the technology being discussed.

An attribute of an object usually consists of a name and a value; of an element, a type or class name; of a file, a name and extension.

  • Each named attribute has an associated set of rules called operations: one doesn't sum characters or manipulate and process an integer array as an image object — one doesn't process text as type floating point (decimal numbers).
  • It follows that an object definition can be extended by imposing data typing: a representation format, a default value, and legal operations (rules) and restrictions ("Division by zero is not to be tolerated!") are all potentially involved in defining an attribute, or conversely, may be spoken of as attributes of that object's type. A JPEG file is not decoded by the same operations (however similar they may be—these are all graphics data formats) as a PNG or BMP file, nor is a floating point typed number operated upon by the rules applied to typed long integers.

See also:

13044 questions
109
votes
6 answers

AttributeError: can't set attribute in python

Here is my code N = namedtuple("N", ['ind', 'set', 'v']) def solve(): items=[] stack=[] R = set(range(0,8)) for i in range(0,8): items.append(N(i,R,8)) stack.append(N(0,R-set(range(0,1)),i)) …
Pratyush Dhanuka
  • 1,405
  • 2
  • 11
  • 21
107
votes
3 answers

ThreadStatic v.s. ThreadLocal: is generic better than attribute?

[ThreadStatic] is defined using attribute while ThreadLocal uses generic. Why different design solutions were chosen? What are the advantages and disadvantages of using generic over attributes in this case?
user2341923
  • 4,537
  • 6
  • 30
  • 44
104
votes
7 answers

Get the name of a pandas DataFrame

How do I get the name of a DataFrame and print it as a string? Example: boston (var name assigned to a csv file) import pandas as pd boston = pd.read_csv('boston.csv') print('The winner is team A based on the %s table.) % boston
leo
  • 1,565
  • 3
  • 11
  • 10
103
votes
20 answers

Determining if all attributes on a javascript object are null or an empty string

What is the most elegant way to determine if all attributes in a javascript object are either null or the empty string? It should work for an arbitrary number of attributes. {'a':null, 'b':''} //should return true for this object {'a':1, 'b':''}…
J-bob
  • 8,380
  • 11
  • 52
  • 85
100
votes
2 answers

Getting the User Agent with JavaScript

I'd like to get a script that can grab the user's user agent and prop it to an attribute. I'm making a website problems contact form and I usually need to know what browser the user is using. How can I detect the user agent string and prop it as the…
henryaaron
  • 6,042
  • 20
  • 61
  • 80
100
votes
18 answers

get the value of DisplayName attribute

public class Class1 { [DisplayName("Something To Name")] public virtual string Name { get; set; } } How to get the value of DisplayName attribute in C# ?
Bassam Bsata
  • 1,075
  • 2
  • 10
  • 13
99
votes
3 answers

How do you define attribute selectors in SASS?

In CSS, you can do this: input[type=submit] { // properties } It's a very useful for styling form buttons. How do you do the same thing in SASS?
Craig Walker
  • 49,871
  • 54
  • 152
  • 212
98
votes
4 answers

Type hinting for properties in PHP 7?

Does php 7 support type hinting for class properties? I mean, not just for setters/getters but for the property itself. Something like: class Foo { /** * * @var Bar */ public $bar : Bar; } $fooInstance = new…
CarlosCarucce
  • 3,420
  • 1
  • 28
  • 51
97
votes
13 answers

hasattr() vs try-except block to deal with non-existent attributes

if hasattr(obj, 'attribute'): # do somthing vs try: # access obj.attribute except AttributeError, e: # deal with AttributeError Which should be preferred and why?
Imran
  • 87,203
  • 23
  • 98
  • 131
96
votes
7 answers

Can't set attributes on instance of "object" class

So, I was playing around with Python while answering this question, and I discovered that this is not valid: o = object() o.attr = 'hello' due to an AttributeError: 'object' object has no attribute 'attr'. However, with any class inherited from…
Smashery
  • 57,848
  • 30
  • 97
  • 128
95
votes
10 answers

Rails: Update model attribute without invoking callbacks

I have a User model that has a :credits attribute. I want a simple button that will add 5 to the user's credits, through a route called "add" so that /users/3/add would add 5 to the credits of user id = 3. def add @user =…
Sam Stern
  • 24,624
  • 13
  • 93
  • 124
95
votes
5 answers

Can I define properties in partial classes, then mark them with attributes in another partial class?

Is there a way I can have a generated code file like so: public partial class A { public string a { get; set; } } and then in another file: public partial class A { [Attribute("etc")] public string a { get; set; } } So that I can…
Chris McCall
  • 10,317
  • 8
  • 49
  • 80
95
votes
5 answers

Removing html5 required attribute with jQuery

Hi I would like to remove the 'required=""' attribute with jquery.
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
93
votes
7 answers

Firefox 4 : Is there a way to remove the red border in a required form input?

When required is defined in a form field, Firefox 4 automatically shows a red border to this element, even BEFORE the user hits the submit button. I think this is disturbing…
Cyril N.
  • 38,875
  • 36
  • 142
  • 243
92
votes
3 answers

A get() like method for checking for Python attributes

If I had a dictionary dict and I wanted to check for dict['key'] I could either do so in a try block (bleh!) or use the get() method, with False as a default value. I'd like to do the same thing for object.attribute. That is, I already have object…
JJ.
  • 4,974
  • 5
  • 39
  • 48