views:

154

answers:

3
for a in ('90','52.6', '26.5'):
    if a == '90':
        z = (' 0',)
    elif a == '52.6':
        z = ('0', '5')
    else:
        z = ('25')

    for b in z:

        cmd = exepath + ' -a ' + str(a) + ' -b ' + str(b) 
        process = Popen(cmd, shell=True, stderr=STDOUT, stdout=PIPE)

        outputstring = process.communicate()[0]
        outputlist = outputstring.splitlines()

        for i in outputlist:
            if i.find('The student says') != -1:
                print i

Working on an assignment and this a snippet of my code. There is a portion above this code but all it's doing is defining exepath and just printing exepath to the screen. When I run this, I don't get an error or anything but the program just ends when put into the command prompt. Why? and how do I fix it?

Sorry for the quotes but the problem is it gives me nothing back it just exits... What could the problem be?

+6  A: 

you are missing quotes around you first for statement try

for a in ('90','52.6', '26.5'):
Josh
Ending quotes FTW!
Fry
Indeed. The OP might consider using a text editor with syntax highlighting to catch this sort of thing.
Kristo
One doesn't need to use a special editor when posting here, since Stack Overflow helpfully shows a highlighted version of the code - as seen above.
Vinay Sajip
+1  A: 

Once you've fixed the missing quote, you'll get weird behavior from this part:

else:
    z = ('25')

for b in z:

the parentheses here do nothing at all, and b in the loop will be '2' then '5'. You probably mean to use, instead:

    z = ('25',)

which makes z a tuple with just one item (the trailing comma here is what tells the Python compiler that it's a tuple -- would work just as well w/o the parentheses), so b in the loop will be '25'.

Alex Martelli
+1  A: 

Looking at your code it will only actually output something if the i.find('The student says') successfully matches so you could either run this in a debugger or add some print statements to see what is in outputstring for each time round the loop.

mikej