Note that there are some explanatory texts on larger screens.

plurals
  1. POPython - Is it possible to get the name of the chained function?
    primarykey
    data
    text
    <p>I'm working on a class that basically allows for method chaining, for setting some attrbutes for different dictionaries stored. </p> <p>The syntax is as follows:</p> <pre><code>d = Test() d.connect().setAttrbutes(Message=Blah, Circle=True, Key=True) </code></pre> <p>But there can also be other instances, so, for example:</p> <pre><code>d = Test() d.initialise().setAttrbutes(Message=Blah) </code></pre> <p>Now I believe that I can overwrite the "setattrbutes" function; I just don't want to create a function for each of the dictionary. Instead I want to capture the name of the previous chained function. So in the example above I would then be given "connect" and "initialise" so I know which dictionary to store these inside.</p> <p>I hope this makes sense. Any ideas would be greatly appreciated :) </p> <p>EDIT:</p> <p>Would this work / Be a good work-around the above problem:</p> <p>Using method overloading, I can have the following methods:</p> <pre><code>def setAttrbutes(self, Name="Foo", Message="", Circle=False): print "Attrbutes method called for 'Foo'" def setAttrbutes(self, Name="Boo", Message=""): print "Attrbutes method called for 'Boo'" </code></pre> <p>So therefore, I can say which method to call depends on the name that is used. For example, in main, if I have the following:</p> <pre><code>d.setAttrbutes(Name="Foo", Message="Hello world", Circle=True) # this will call the first d.setAttrbutes(Name="Boo", Message="Hello world") # this will call the second </code></pre> <p>Would this work, and, if not, why?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload