Commits

Gael Pasgrimaud  committed 18a6f65

add pythonic way to play with attributes

  • Participants
  • Parent commits f044bd0

Comments (0)

Files changed (2)

File pyquery/README.txt

     >>> p.attr("id", "hello")
     [<p#hello.hello>]
 
+Or the pythonic way::    
+
+    >>> p.id
+    'hello'
+    >>> p.id = "plop"
+    >>> p.id
+    'plop'
+    >>> p.id = "hello"
+
 And the class::
 
     >>> p.addClass("toto")

File pyquery/pyquery.py

                 tag.set(name, value)
         return self
 
+    def __setattr__(self, name, value):
+        return self.attr(name, value)
+
+    def __getattr__(self, name):
+        return self.attr(name)
+
     def removeAttr(self, name):
         for tag in self:
             del tag.attrib[name]
         return self
 
+    def __delattr__(self, name):
+        self.removeAttr(name)
+
     #######
     # CSS #
     #######