On 12/12/06, at 7:05 AM, Jacob Rus said:
#3: super() in class snippet
It would be cool if the class snippet inserted super(...) into the constructor for the class. (Is this possible with clever mirroring?)
How would this work? Can you give an example?
In Action:
class SuperSnippetInAction(object): """docstring for SuperSnippetInAction""" def __init__(self, arg): super(SuperSnippetInAction, self).__init__() self.arg = arg
The 5th tab selects the whole "super..." line, for easy "fixing". (I suppose tab 5 could be places in between the ()s of the __init__ call, for easy parameter adding too
The Snippet:
class ${1:ClassName}(${2:object}): ${3/.+/"""/}${3:docstring for $1}${3/.+/"""\n/}${3/.+/\t/}def __init__(self${4/([^,])?(.*)/(?1:, )/}${4:arg}): ${5:super($1, self).__init__()} ${4/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][a-zA-Z0-9_]*)\s*(=[^,]*)?(,\s*|$)/(?2:\t\tself.$2 = $2\n)/g} ${0:${4/(\A\Z|\A\s*,\s*\Z)|(.+)/(?1:pass)(?2:)/}}
Or, instead of super, I suppose this could be replaced with $2.__init__()
Thanks to all who replied (and pointed me to dict(), which I didn't know about. Cool!)
Hope this helps, _Ryan Wilcox