Python script - complete execution of one line before the ne

This is the place for queries that don't fit in any of the other categories.

Python script - complete execution of one line before the ne

Postby pcd » Thu May 22, 2014 7:22 pm

Hi,

Perhaps someone can help with this problem. For info - Choicebox is an enigma2 gui class - this is not important for my question.

Code: Select all
SELECTION = " "
def main(session, **kwargs):
        res = openTest(session)
        print "res =", res

def openTest(session):
        session.openWithCallback(test1, ChoiceBox, title="Select playlist item?", list=[(_("Video1"), "Video1"), (_("Video2"), "Video2"), (_("Video3"), "Video3"), (_("Video4"), "Video4"), (_("Video5!"), "Video5")])   
        return SELECTION
               
               
def test1(answer):
      print "answer A:", answer
      global SELECTION
      SELECTION = answer[1]


Question :- This code prints res = None. Obviously the print line is executed before openTest is completed. Without changing def main - how can the correct reply 'res' be returned and printed ?

Regards, pcd.
Last edited by Yoriz on Thu May 22, 2014 9:32 pm, edited 1 time in total.
Reason: First post lock.
pcd
 
Posts: 1
Joined: Thu May 22, 2014 7:12 pm

Re: Python script - complete execution of one line before th

Postby Kebap » Fri May 23, 2014 9:37 am

Hi pcd, your function openTest returns the value of SELECTION, but that is never defined there. I assume this is why None is returned.

Other than that, can you show some code with the same error, but without openWithCallback or ChoiceBox etc, so we can actually run and test it ourselves?
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 366
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests