2013-11-28 124 views
0

我需要爲3個變量(加油站,酒店,食物聯合)創建循環,以便一個接一個地執行一個接一個地執行相同的函數,..如果任何人能夠指導我這3個變量的循環函數

我曾用C試過相同,任何一個可以請幫我做的Python

CHAR sMenuNames[3][30]={ {'GAS STATTION'}, {'Hotel'}, {'Restaurant'} } 
CHAR sCurrentMenuName[30]; 
INTEGER nCount; 
INTEGER nMaxCount =4; 
For(ncount=1;nCount<=nMaxCount;ncount++) 
{ 
sCurrentMenuName=sMenuNames[ncount] 
//EXECUTE_FUNCTIONS(sCurrentMenuName); 
wait 20 
} 

需要它的自動化配置文件(蟒蛇robotframe腳本)

+1

請提供預期的輸入和輸出,這將有助於使問題更好:) – aIKid

回答

0

這應該是幫幫我。我試圖用python編寫你的代碼。

import time 

variables = ['GAS STATTION', 'Hotel', 'Restaurant'] 

for item in variables: 
    #run your functions here 
    func1(item) 
    func2(item) 
    func3(item) 

    #similar to your wait(20) 
    time.sleep(20) 
0

它看起來像你想要的東西。

menu_names = ['GAS STATION', 'Hotel', 'Restaurant'] 
for menu_name in menu_names: 
    execute_functions(menu_name) 

沒有必要定義字符串和列表的大小。您不需要索引來訪問列表中的每個元素,只需對其進行迭代即可。