Way to pass multiple parameters to a function in python

前端 未结 6 1786
遇见更好的自我
遇见更好的自我 2021-02-06 09:12

I have written a python script which calls a function. This function takes 7 list as parameters inside the function, something like this:

def WorkDetails(link, A         


        
6条回答
  •  被撕碎了的回忆
    2021-02-06 09:44

    You can change it to:

    def WorkDetails(link, details):
    

    Then invoke it as:

    details = [ AllcurrValFound_bse, AllyearlyHLFound_bse, 
                AlldaysHLFound_bse, AllvolumeFound_bse, 
                AllprevCloseFound_bse, AllchangePercentFound_bse, 
                AllmarketCapFound_bse ]
    workDetails(link, details)
    

    And you would get the different values out of details by:

    AllcurrValFound_bse = details[0]
    AllyearlyHLFound_bse = details[1]
    ...
    

    It would be more robust to turn details into a dictionary, with the variable names as keys, so take your pick between a few more lines of code vs. defensive programming =p

提交回复
热议问题