Python: variable parameters and apply

Source: Internet
Author: User

I think it is a relatively advanced usage in Python. I don't know if it is available in C. The special thing here is that since an interface has been made public, I cannot modify the function prototype, however, another function that accepts a parameter needs to pass the parameter it receives to a public function (of course, the data is correct). Therefore, you need to do so.

 #  ! /Usr/bin/ENV Python  #  -*-Coding: UTF-8 -*-  '''  A very advanced usage in Python: applyapply accepts two parameters: function pointers and meta groups (it seems that there are other more advanced usage). When applying calls a function executed by a function pointer, splits the tuples into parameter lists and passes them to the function.  '''  Import  Weburls = (  '  /App1  ' , '  App1  '  ,  '  /App2  ' , '  App2  '  ,  '  /App3/(\ W *)  ' , '  App3  ' ,  '  /App4/(\ W *)  ' , '  App4  ' , #  Agreed Interface  ) Web. config. Debug = Falseapp = Web. Application (URLs, globals ())  Class  Pagebase:  Def  _ Init __  (Self): Self. funget = Self. Get self. Get = Self. Get  Def Get (self ,* ARGs): wi = Web. Input ()  If Hasattr (WI, "  ID  "  ): Self. s = WI. ID  Else : Self. s = "  Hello  "                  #  Pay attention to the apply call. For more information about this function, seeCodeTop          Return  Apply (self. funget, argS)  Class  App1 (pagebase ):  Def  Get (Self ):  Return  Self. s  Class App2 (pagebase ):  Def  Get (Self ):  Return  Self. s  Class  App3 (pagebase ):  Def  Get (self, ID ):  Return  ID  Class  App4 (pagebase ):  #  The interface has been agreed, and I do not have permission to declare that this function supports variable parameters.      Def Get (self, id1, Id2 ):  Return Id1 + "  ,  " + Id2  If   _ Name __ = "  _ Main __  "  : App. Run () 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.