I would like to use a decorator for validating data in Python. Normally in Python one uses a decorator on a function, but I would like to use a decorator on a variable, similar to Java:
public class Main {
public static void main(String[] args) {
@BoldWrapper
@ItalicWrapper
String str = "Hello World";
// Display <b><i>Hello World</i></b>
}
}
public @interface BoldWrapper {
public void wrap() default "<b>" + str + "</b>";
}
public @interface ItalicWrapper {
public void wrap() default "<i>" + str + "</i>";
}
So in Python I would have something like:
if __name__ == '__main__':
@BoldWrapper
@ItalicWrapper
str = "Hello World";