2016-11-28 6 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!' 

私はbook idsのリストを持っています。そして、これらの数値を変数の予約に渡して、イベントを削除したいと思います。リストの要素を変数に渡す方法

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リストの要素を渡すことができますどのように?

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

arg_listリストにself.bidsリストから単一の項目を追加し

arg_list.append(self.bids[0]) 

と同等です:何をやっているあなたの現在のコードで

+1

"for"ループを試しましたか? もう一度、 " - objectId ="引数に 'BOOK:688045640'または '688045640'だけを渡しますか – SunilT

答えて

0

arg_listの最後に全体self.bidsリストを追加するには、代わりに.extendメソッドを使用します。

arg_list += self.bids 

arg_list.extend(self.bids) 

別のオプションは、既存のリストを拡張します+=代入演算子を使用することです

ところで、あなたのsubprocess.call(["python", arg_list])はちょっと変です。 the docsに示すように、それはUPNP_Client_Cmd_Lineモジュールをインポートして、直接その機能を呼び出すために、はるかに効率的である、しかし

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

でなければなりません。

関連する問題