2016-11-28 67 views
0
def delete_events(self): 


    self.ucn = self.user_channel_number 
    print 'The channel number in the process: ', self.ucn 

    self.bids = self.channel_events_book_ids 
    print 'Events book ids', self.bids 
    print '', len(self.bids), 'events on the planner will be deleted' 

    are_you_sure = raw_input('Channel number is correct. Are you sure to delete channel number? (y/n): ') 

    if are_you_sure == 'y' and len(self.bids) !=0 : 

     print 'The selected program will be deleted' 

     action = 'DeleteEvent' 
     menu_action = 'all' 
     book = self.bids[0] 
     arg_list = [('C:\\Users\\yke01\\Documents\\StormTest\\Scripts\\Completed' 
         '\\Utils\\UPNP_Client_Cmd_Line.py')] 
     arg_list.append(' --action=') 
     arg_list.append(action) 
     arg_list.append(' --ip=') 
     arg_list.append('10.10.8.89') 
     arg_list.append(' --objectId=') 
     arg_list.append(book) 

     subprocess.call(["python", arg_list]) 

     print 'The program deleted successfully' 

    else: 
     print 'The program is NOT deleted!' 

我已經獲得了書目ID的列表。我想通過這些數字來預訂變量來刪除事件。如何將列表中的元素傳遞給變量

output of bookids samples : ['BOOK:688045640', 'BOOK:688045641', 'BOOK:688045642', 'BOOK:688045643', 'BOOK:688045644', 'BOOK:688045645', 'BOOK:688045646', 'BOOK:688045647'] 

我可以刪除與下列動作單一事件:

book = self.bids[0] 

如何我可以通過bookids列表元素預定變量?

+1

你試過用「for」循環嗎? 您是否還想將「BOOK:688045640」或「688045640」傳遞給「--objectId =」參數 – SunilT

回答

0

在你當前的代碼你正在做的:

book = self.bids[0] 
# ... 
arg_list.append(book) 

這相當於

arg_list.append(self.bids[0]) 

self.bids列表中arg_list列表追加單個項目。整個self.bids列表中添加到arg_list年底,使用.extend方法代替:

arg_list.extend(self.bids) 

另一種選擇是使用+=賦值運算符將擴展現有的列表:

arg_list += self.bids 

順便說一句,你的subprocess.call(["python", arg_list])有點奇怪。正如the docs所示,它應該是

subprocess.call(["python"] + arg_list) 

然而,這將是更有效導入UPNP_Client_Cmd_Line模塊直接調用其功能。