python - How do I instantiate an object without assigning a variable to it -


I have a class whose __ init __ function is a bunch of content, and it All i need

So I really want to call the __init __ function of this class. How can I do this without assigning it to a variable? Firstly, it is clearly a design error - this code should be just a standalone function.

However, there are a few ways you can do this:

  1. Just start the process normally - there is no reason that you will get the result of an expression Specify in a variable However, this will result in the creation of a complete object (and possibly possibly destruction soon).

      Foo ()    
  2. Built-in function call:

      Foo___word __ Receive ('__ init __') (none)     

    This will not trigger the object creation, but you probably do not want to note that here In the example, I passed the value of a as the value of self . This only works when __init __ self does not do anything (or, it is where it handles no )

    2a You can use staticmethod to make it easier:

     in  [32]: square fu (object): ....: @staticmethod ....: def __init __ ( ): ... .print "Fu Init" ....: in [33]: Fu () Fu Init Out [33]:    

Comments