What is the current state of the “scoped” attribute for the style element in HTML5?

Many of the answers here have become somewhat obsolete, so here goes a brief summary of what happened with the scoped attribute. Originally (before HTML5), <style> was not “valid” outside <head>, but was supported by most or all browsers. “not valid” means that validators would complain about it, and the specs (W3C’s HTML 4 and … Read more

How do I set permissions (attributes) on a file in a ZIP file using Python’s zipfile module?

This seems to work (thanks Evan, putting it here so the line is in context): buffer = “path/filename.zip” # zip filename to write (or file-like object) name = “folder/data.txt” # name of file inside zip bytes = “blah blah blah” # contents of file inside zip zip = zipfile.ZipFile(buffer, “w”, zipfile.ZIP_DEFLATED) info = zipfile.ZipInfo(name) info.external_attr … Read more

How do Perl method attributes work?

You are right, the documentation is not very clear in this area, especially since attributes are not so complicated. If you define a subroutine attribute, like this: sub some_method :Foo { } Perl will while compiling your program (this is important) look for the magic sub MODIFY_CODE_ATTRIBUTES in the current package or any of its … Read more

JavaScript: changing the value of onclick with or without jQuery

You shouldn’t be using onClick any more if you are using jQuery. jQuery provides its own methods of attaching and binding events. See .click() $(document).ready(function(){ var js = “alert(‘B:’ + this.id); return false;”; // create a function from the “js” string var newclick = new Function(js); // clears onclick then sets click using jQuery $(“#anchor”).attr(‘onclick’, … Read more

How to assign a new class attribute via __dict__?

There is a builtin function for this: setattr(test, attr_name, 10) Reference: http://docs.python.org/library/functions.html#setattr Example: >>> class a(object): pass >>> a.__dict__[‘wut’] = 4 Traceback (most recent call last): File “<stdin>”, line 1, in <module> TypeError: ‘dictproxy’ object does not support item assignment >>> setattr(a, ‘wut’, 7) >>> a.wut 7

Python: Make class iterable

Add the __iter__ to the metaclass instead of the class itself (assuming Python 2.x): class Foo(object): bar = “bar” baz = 1 class __metaclass__(type): def __iter__(self): for attr in dir(self): if not attr.startswith(“__”): yield attr For Python 3.x, use class MetaFoo(type): def __iter__(self): for attr in dir(self): if not attr.startswith(“__”): yield attr class Foo(metaclass=MetaFoo): bar … Read more

XSD element with both attributes and child elements

This is one possible way to define an XSD matching your XML; when learning XSD, you could enroll the help of a tool that infers the XSD for you, starting from one or more XML sample files. <?xml version=”1.0″ encoding=”utf-8″?> <!–W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)–> <xsd:schema attributeFormDefault=”unqualified” elementFormDefault=”qualified” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”> <xsd:element name=”component”> … Read more

When should I use attribute in C#?

In the .NET Framework, attributes can be used for many reasons — like Defining which classes are serializable Choosing which methods are exposed in a Web service Attributes allow us to add descriptions to classes, properties, and methods at design time that can then be examined at runtime via reflection. Consider this example: Say you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)