Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can the name of a class be set automatically in a data attribute of an instance of that class in Python?
    primarykey
    data
    text
    <p>How can the name of a class be set automatically in a data attribute of an instance of that class?</p> <p>Here is some example code:</p> <pre><code>def workFunctionTest(**kwargs): time.sleep(3) return kwargs def printHR(object): # dictionary if isinstance(object, dict): for key, value in sorted(object.items()): print u'{0}: {1}'.format(key, value) # list or tuple elif isinstance(object, list) or isinstance(object, tuple): for element in object: print element # other else: print object class Job(object): def __init__( self, workFunction=workFunctionTest, workFunctionArguments={'testString': "hello world"}, naturalLanguageString=None ): self.workFunction=workFunction self.workFunctionArguments=workFunctionArguments, self.naturalLanguageString=naturalLanguageString def printout(self): """ This method prints a dictionary of all data attributes. """ printHR(vars(self)) def main(): job1=Job( workFunction=workFunctionTest, workFunctionArguments={'testString': "hello world"}, ) print("Is the object an instance of the class?") print isinstance(job1, Job) print("a printout generated by a method of the object:") job1.printout() if __name__ == '__main__': main() </code></pre> <p>How could the end of the printout from this code be changed from this:</p> <pre><code>naturalLanguageString: None workFunction: &lt;function workFunctionTest at 0x7f435461ac80&gt; workFunctionArguments: ({'testString': 'hello world'},) </code></pre> <p>to this?:</p> <pre><code>naturalLanguageString: Job workFunction: &lt;function workFunctionTest at 0x7f435461ac80&gt; workFunctionArguments: ({'testString': 'hello world'},) </code></pre>
    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.
    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