Python Forum
[xbmc] How to block the code from executed twice under the loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[xbmc] How to block the code from executed twice under the loop
#28
(Oct-26-2016, 02:33 PM)chris0147 Wrote: When I try this:
program_id = ('\n'.join(some_list))
ctrl = self.getControl(int(program_id))
I will get an error: [b]ValueError: invalid literal for int() with base 10: '3001\n3011\n3021\n3031\n3041\n3051\n3061'

Any idea how I can fix this??

What are you trying to do?  You're taking a list of things, and combining them it create a newline-separated string.  All of those things, all at once, are not an int, they're just a string.  Each individual item is an int, but all of them are just a big string.  So fixing it depends on what you want to do.  Do you want to loop over all of them and do something with each?  And, if so, they probably shouldn't be joined together.
for program_id in some_list:
   ctrl = self.getControl(int(program_id))
   # do something with this ctrl/program_id
Reply


Messages In This Thread
RE: [xbmc] How to block the code from executed twice under the loop - by nilamo - Oct-26-2016, 02:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] messagebox is not being executed please help erwinsiuda 2 2,383 Apr-02-2020, 01:56 AM
Last Post: Larz60+
  [Tkinter] Window unresponsive when executed. fawazcode 2 3,894 Sep-11-2017, 12:29 AM
Last Post: Larz60+
  [WxPython] Which def is executed? merlem 10 8,048 Feb-10-2017, 11:28 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020