Marko,
You have lots of options, with one already presented (augment sys.path and use import). Here are a couple more that I've used:
Execute an argument containing source supplied on the commmand line: mycode.exe -c 'print "hello" ; import math ; print math.sqrt(2)'
gns = dictionary of global symbols I want to expose, e.g., globals()
code = compile(args.command+'\n', "command line", "exec")
exec(code, gns)
Collect the name of the file that the users wants executed and simply execute it:
filename = "usercode.py"
execfile(filename, gns)
The first example is very general, get some source in a string, compile it and execute it. The second is really just shorthand for doing exactly that.
HTH,
Eric
From: Marko Loparic [mailto:marko.loparic@...]
Sent: Tuesday, February 12, 2013 02:59
To: py2exe-users@...
Subject: [Py2exe-users] Execute non-compiled code from a py2exe executable
Hello,
Is there a way to make a py2exe compiled code execute a non-compiled python code (without installing python)?
The idea is let part of the code non-compiled to allow the users to easily make some changes. They have windows non-admin access to their machine so in principle they can't install python.
Thanks for any hint! Cheers,
Marko
|