#euler's method in the forum is very cool and straightforward #had a lot of troubles generating the products list #(that's all why it took me forever to find out) #learned how to use yield and recursion on yield (cool stuff) from MathLib import isPrime #Maple initializations #subprocess version from subprocess import Popen, PIPE maple = Popen(['maple', '-t', '-u', '-q'], stdin=PIPE, stdout=PIPE, stderr=None, close_fds=True) #use numtheory package to find divisors of a number maple.stdin.write('with(numtheory):\n') ''' #Pexpect version (SLOW) import pexpect maple = pexpect.spawn('maple -t -u') maple.expect('#-->') maple.sendline('with(numtheory):') maple.expect('#-->') ''' def ask_maple(command): #subprocess version #can be easily deadlocked if calling stdout.readline() more than #the output actually has maple.stdin.write(command + ';EndofLine;\n') t = "" t = maple.stdout.readline().strip()