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

2024-10-02 00:38:51 发布

您现在位置:Python中文网/ 问答频道 /正文

两种不同情况下的输入文件:

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

现在在案例1中,我只有一个开始和结束值01和05

我的功能是:

^{pr2}$

在案例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.

我的程序执行流程与案例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 

Tags: tonoinputifisdeviceflowone
1条回答
网友
1楼 · 发布于 2024-10-02 00:38:51

我不确定我是否理解这个问题。但根据我的理解,我认为您希望函数能够接受可变数量的参数:

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

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

请告诉我这是不是你要找的?在

相关问题 更多 >

    热门问题