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
#21
Is this what your working on? 
https://github.com/xbmc/xbmc
Reply
#22
(Oct-25-2016, 07:08 PM)Yoriz Wrote: Of course it makes a difference, each gui framework has its own way of doing things , its own methods ect.
Without knowing and your lack of showing enough useful code no one can have a clue whats going on.
Your coding and explanations are terrible.
Your lucky I'm wasting my time to even try and fathom out what the hell you are doing.

I'm sorry that my coding and explaition are terrible, but I am trying my best all I can do to get you to understand what I am trying to do.

If you want to take a look on my code to know what I am doing, here it is: http://pastebin.com/TZ24Bn0Y


Here is what I am trying to do: I want to get the 7 program ids from the variable called pos_X, so I can store the ids in the list. Then the next thing I want to do is to find the buttons with the follow ids that I stored in the list. I want to find what size the button1 need to change like change from 691 to 344 and if I have a button size like 167, 344 or whatever it is, I want to change the button1 size that I got it from button2. And also I want to change the button2 size that I got it from button3, change button3 size that I got the size from button4 and so on. I hope you get this now what I am trying to do.

(Oct-25-2016, 07:10 PM)metulburr Wrote: Is this what your working on? 
https://github.com/xbmc/xbmc

Yep, that is what I am working on. I am working on my own addon. Wink
Reply
#23
OMG Think Hypnotic
How the hell can you or anyone follow such a huge method with all those condition statements in condition statements (reoccurring)
Reply
#24
(Oct-25-2016, 07:18 PM)chris0147 Wrote: I'm sorry that my coding and explaition are terrible, but I am trying my best all I can do to get you to understand what I am trying to do.
For future reference when we ask what library you are using you could respond with something like...

i dont know but there is an import line like this at the top
import xbmc
import xbmcgui
as well as what you were working on to give us a better understanding such as the github repo link

Quote:If you want to take a look on my code to know what I am doing, here it is: http://pastebin.com/TZ24Bn0Y
Your code although sometimes useful to have the entire thing.....this one gives me a headache to look at. I dont even know where to start.
Reply
#25
(Oct-25-2016, 07:34 PM)metulburr Wrote:
(Oct-25-2016, 07:18 PM)chris0147 Wrote: I'm sorry that my coding and explaition are terrible, but I am trying my best all I can do to get you to understand what I am trying to do.
For future reference when we ask what library you are using you could respond with something like...

i dont know but there is an import line like this at the top
import xbmc
import xbmcgui
as well as what you were working on to give us a better understanding such as the github repo link

Quote:If you want to take a look on my code to know what I am doing, here it is: http://pastebin.com/TZ24Bn0Y
Your code although sometimes useful to have the entire thing.....this one gives me a headache to look at. I dont even know where to start.

The version for xbmc is 12.2 and gui version is 4.0.0.

I don't think there is anything have to do with gui version, it is just the code that I am working on which it dont seen right.

I guess that I am stuck with storing the program ids in the list.


    test_id = list()

    #Store the list of strings in the lists
        for i in range(len(posX)):
            pos_X = posX[i]

            if pos_X == '375':
                self.program_id = list()
                self.program_id.append(programs_id[i])

    for program_id in self.program_id:
        test_id_list = list()
        test_id_list.append(program_id)

    print "test_id"
    print test_id
    
   program_id = ''.join(str(x) for x in test_id_list)
Do you know how I can store each id at a time and make the output like this?


Quote:['3001']
['3011']
['3021']
['3031']
['3041']
['3051']
['3061']


instead of this?

Quote:['3001', '3011', '3021', '3031', '3041', '3051', '3061']



I want to store one id in the list at a time and find the control that I want to use to change the size before I could empty the list and store the next id then find the control that I want to use to change the size I want. It can repeats until there is no more id when I'm searching for the id in the pos_X area.

I think it is only way to do this to avoid the looping otherwise it will looping and the code will executing like three times. If I use the single id, I don't think I would have any problem as I would be able to have the code to execute only once when I use for each id.

Can you be able to help me with that?
Reply
#26
Instead of "print(some_list)", try "for item in some_list: print(item)". Or perhaps "print('\n'.join(some_list))".

And now that that question is answered, here's a few tips on making that small snippet better:
1) Instead of "some_list = list()", try "some_list = []"
2) Instead of "for ndx in range(len(some_list)):", try "for item in some_list:"
3) Instead of "some_list = list(); some_list.append(some_thing)", try "some_list = [some_thing]"

Small little improvements to readability would go miles to helping other people quickly see what's going on in your code.
Reply
#27
(Oct-25-2016, 10:29 PM)nilamo Wrote: Instead of "print(some_list)", try "for item in some_list: print(item)".  Or perhaps "print('\n'.join(some_list))".

And now that that question is answered, here's a few tips on making that small snippet better:
1) Instead of "some_list = list()", try "some_list = []"
2) Instead of "for ndx in range(len(some_list)):", try "for item in some_list:"
3) Instead of "some_list = list(); some_list.append(some_thing)", try "some_list = [some_thing]"

Small little improvements to readability would go miles to helping other people quickly see what's going on in your code.

Thank you for your advise.

When I try this:


program_id = ('\n'.join(some_list))

ctrl = self.getControl(int(program_id))
I will get an error: ValueError: invalid literal for int() with base 10: '3001\n3011\n3021\n3031\n3041\n3051\n3061'

The error are jumping on this line:

ctrl = self.getControl(int(program_id))
Any idea how I can fix this??

(Oct-25-2016, 07:34 PM)metulburr Wrote:
(Oct-25-2016, 07:18 PM)chris0147 Wrote: I'm sorry that my coding and explaition are terrible, but I am trying my best all I can do to get you to understand what I am trying to do.
For future reference when we ask what library you are using you could respond with something like...

i dont know but there is an import line like this at the top
import xbmc
import xbmcgui
as well as what you were working on to give us a better understanding such as the github repo link

Quote:If you want to take a look on my code to know what I am doing, here it is: http://pastebin.com/TZ24Bn0Y
Your code although sometimes useful to have the entire thing.....this one gives me a headache to look at. I dont even know where to start.

I have posted yesterday but haven't heard from you. can you help??
Reply
#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
#29
(Oct-26-2016, 02:55 PM)nilamo Wrote:
(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

I am trying to loop over them at a time and change the width size I want.

I have found a solution to block the code from looping as I have to use a if statement to block it so thanks anyway...
Reply
#30
You're welcome :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] messagebox is not being executed please help erwinsiuda 2 520 Apr-02-2020, 01:56 AM
Last Post: Larz60+
  [Tkinter] Window unresponsive when executed. fawazcode 2 1,786 Sep-11-2017, 12:29 AM
Last Post: Larz60+
  [WxPython] Which def is executed? merlem 10 4,347 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