简体   繁体   English

使用不同的参数多次调用相同的函数python

[英]calling same functions in multiple times with different arguments python

Input file in two different cases: 两种不同情况下的输入文件:

case1:

inputfile:

one-device:yes
number of device:01-05
first-device:
second-device:

Case2:
one-device:no
number of device:01-05
first-device:01-03
second-device:04-05

Now in case 1 i have only one start and end value that is 01 and 05 现在在情况1中,我只有一个起始值和结束值,分别是01和05

Functions I have is: 我拥有的功能是:

def func1(self, start, end):
     for i, x in enumerate (range(start, end)):
         do something
def func10 (self, start, end):
         do something

case 2: i have 2 different start and end value that is for first device 01-03 and 04-05.

In case 1 my program execution flow. 在情况1中,我的程序执行流程。

# if one-device input is yes
func1(arg1, agr2)
func2(arg1, agr2)
func3(arg1, agr2)
func4(arg1, agr2)
func5(arg1, agr2)
func6(arg1, agr2)
func7(arg1, agr2)
func8(arg1)
func9(arg1, agr2,arg3)
func10(agr1,arg2)
func11(arg1, agr2)
func12(arg1, agr2)
func13(arg1) 


#if one-device input is no.
#In  case2. i need to call two times functions func1 and func10.

my program execution flow like for case 2 is: 我的程序执行流程类似于案例2:

# run two times with two diffewnt start and end values as per input in case 2
func1(arg1, agr2)
func1(arg1, agr2)


#flow continues as usal 
func2(arg1, agr2)
func3(arg1, agr2)
func4(arg1, agr2)
func5(arg1, agr2)
func6(arg1, agr2)
func7(arg1, agr2)
func8(arg1)
func9(arg1, agr2,arg3)
# run two times with two diffewnt start and end values as per input in case 2
func10(agr1,arg2)
func10(agr1,arg2)


#flow continues as usal 
func11(arg1, agr2)
func12(arg1, agr2)
func13(arg1)


Now question is i want to use if else statement to check one-device is yes or no.

if one-device  is yes  write case 1  flow

if one-device  is no  write case 1  flow 

if no write same flow with using for loop for func1 and func10 to run two  times.

If i use this method my code be be lot of duplicate .

I need help here 

I'm not sure if I understood the question. 我不确定我是否理解这个问题。 But from what I understood, I think you want the function to be able to accept variable number of arguments: 但是据我了解,我认为您希望函数能够接受可变数量的参数:

def f1(arg1, *args):
    print "first arg: ", arg1
    for arg in args:
        print "next arg:", arg

f1(1, "string", 3,4)

Please let me know if this is what you were looking for? 请让我知道这是您要找的东西吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用不同的参数多次调用同一个函数? - Calling the same function multiple times with different arguments? 在 Python (3.x) 中使用不同的参数连续多次调用函数? - Calling a function multiple times consecutively with different arguments in Python (3.x)? 使用不同的参数多次运行python函数 - Run python function multiple times with different arguments 多线程(在python中)与多次调用脚本相同吗? - Is Multithreading (in python) the same as calling the script multiple times? 将相同的参数传递给多个函数-Python - Passing same arguments to multiple functions - Python 是否有更有效的方法多次调用具有不同参数的函数? - Is there a more efficient way to call functions with different arguments multiple times? Python 如何保持相同的运行 function 与不同的 arguments 在 ZDB974238714038DE63ZA7ACED1 中多次并行 - Python How to keep running same function multiple times parallel with different arguments in API 多次不同时间调用同一个 function 的最佳做法是什么 - What is the best practice for calling the same function multiple different times 多个函数作为python中的参数 - multiple functions as arguments in python Python 具有多个 arguments 的函数 - Python Functions with multiple arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM