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
2383
votes
16 answers

How to check if an object has an attribute?

How do I check if an object has some attribute? For example: >>> a = SomeClass() >>> a.property Traceback (most recent call last): File "", line 1, in AttributeError: SomeClass instance has no attribute 'property' How do I tell if…
Lucas Gabriel Sánchez
  • 40,116
  • 20
  • 56
  • 83
1365
votes
8 answers

What is the purpose of the "role" attribute in HTML?

I keep seeing role attributes in some people's work. I use it too, but I'm not sure about its effect. For example: Or:
jeroen
  • 13,760
  • 3
  • 16
  • 10
941
votes
7 answers

What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

There are three assembly version attributes. What are differences? Is it ok if I use AssemblyVersion and ignore the rest? MSDN says: AssemblyVersion: Specifies the version of the assembly being attributed. AssemblyFileVersion: Instructs a…
Jakub Šturc
  • 35,201
  • 25
  • 90
  • 110
886
votes
21 answers

Difference between id and name attributes in HTML

What is the difference between the id and name attributes? They both seem to serve the same purpose of providing an identifier. I would like to know (specifically with regards to HTML forms) whether or not using both is necessary or encouraged for…
yogibear
  • 14,487
  • 9
  • 32
  • 31
545
votes
5 answers

Why use Ruby's attr_accessor, attr_reader and attr_writer?

Ruby has this handy and convenient way to share instance variables by using keys like attr_accessor :var attr_reader :var attr_writer :var Why would I choose attr_reader or attr_writer if I could simply use attr_accessor? Is there something like…
Saturn
  • 17,888
  • 49
  • 145
  • 271
491
votes
20 answers

Python dictionary from an object's fields

Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this: >>> class Foo: ... bar = 'hello' ... baz = 'world' ... >>> f = Foo() >>> props(f) { 'bar' : 'hello', 'baz' :…
Julio César
  • 12,790
  • 10
  • 38
  • 45
441
votes
4 answers

Specify multiple attribute selectors in CSS

What is the syntax for doing something like: input[name="Sex" AND value="M"] Basically, I want to select the input element that has the attribute name="Sex" as well as the attribute value="M": Elements…
John
  • 32,403
  • 80
  • 251
  • 422
421
votes
19 answers

How can I create an object and add attributes to it?

I want to create a dynamic object (inside another object) in Python and then add attributes to it. I tried: obj = someobject obj.a = object() setattr(obj.a, 'somefield', 'somevalue') but this didn't work. Any ideas? edit: I am setting the…
John
  • 21,047
  • 43
  • 114
  • 155
408
votes
32 answers

Accessing dict keys like an attribute?

I find it more convenient to access dict keys as obj.foo instead of obj['foo'], so I wrote this snippet: class AttributeDict(dict): def __getattr__(self, attr): return self[attr] def __setattr__(self, attr, value): self[attr]…
Izz ad-Din Ruhulessin
  • 5,955
  • 7
  • 28
  • 28
356
votes
1 answer

List view getListItemXmlAttributes method fails with child publication items

I have created a JS class to populate SG/Folder list view data, when items are modified. (As per Jaime's approach) Everything works great when I operate on items in the publication they're created in. Ex: I open a component or page and the custom…
Warner Soditus
  • 4,123
  • 2
  • 14
  • 10
346
votes
2 answers

correct way to define class variables in Python

I noticed that in Python, people initialize their class attributes in two different ways. The first way is like this: class MyClass: __element1 = 123 __element2 = "this is Africa" def __init__(self): #pass or something else The other…
jeanc
  • 4,563
  • 4
  • 22
  • 27
334
votes
22 answers

private final static attribute vs private final attribute

In Java, what's the difference between: private final static int NUMBER = 10; and private final int NUMBER = 10; Both are private and final, the difference is the static attribute. What's better? And why?
okami
327
votes
5 answers

How do I remove the "extended attributes" on a file in Mac OS X?

I have an AppleScript script that runs a stress test. Part of the test is to open, save, and close certain files. Somehow, the files have picked up some "extended attributes" that prohibit the files from being saved. That causes the stress test to…
tames
  • 3,279
  • 3
  • 17
  • 4
304
votes
13 answers

When to use setAttribute vs .attribute= in JavaScript?

Has a best-practice around using setAttribute instead of the dot (.) attribute notation been developed? E.g.: myObj.setAttribute("className", "nameOfClass"); myObj.setAttribute("id", "someID"); or myObj.className = "nameOfClass"; myObj.id =…
Francisc
  • 77,430
  • 63
  • 180
  • 276
283
votes
3 answers

How to access (get or set) object attribute given string corresponding to name of that attribute

How do you set/get the values of attributes of t given by x? class Test: def __init__(self): self.attr1 = 1 self.attr2 = 2 t = Test() x = "attr1"
Nullpoet
  • 10,949
  • 20
  • 48
  • 65
1
2 3
99 100