So.....Basically recently I just faced with some problem. I wanted to create my own data type. I created new class put something in it. But I really wanted to set items in it like so: ======== >>>datatype[0][0][1]=1 ======== As you could see I used 3 keys.... But magic method __setitem__ alows me only to do something like this: ======= >>>datatype[0,0,1]=1 ======= And that's a little bit uncomortable. Also...I know that probably everyone sometime wanted to 'hide' class name when you create object and not to write this: ======= >>>var=MyClass('David') ======= ...And instead to write this: ======= >>>var=<David> >>>var <__main__.MyClass object at 0x0000006242B13748> ======= I think that would be much easier and glamourus. So here I present you special type of object: pattern
Example: ======= >>>&mypattern='<'str'>' ====== Here I created variable that stored pattern This pattern allows me to write '<>' with string in this For example from that momemnt if I type '<Example>' Nothing will happen. Also patterns can have commands in them: ====== >>>&mynewpattern='#'list'#' >>> def &mynewpattern: ... return MyClass(list) ====== Here I gave pattern 'mynewpattern' functionality. Now it RETURNS CLASS!!! This way we could make shorter and more beautiful.In the example list is type of data like string or integer. And now I made that when I type lists with '#'s program returns class MyClass. That's concludes explanation of patterns P.S. Ask me in comments if you didnt understand something. -- https://mail.python.org/mailman/listinfo/python-list