yade-users team mailing list archive
-
yade-users team
-
Mailing list archive
-
Message #03858
Re: Launching scripts inside Yade ?
> Thanks but this does not work. I get by this way plenty of errors about
> python functions (I want to use during the execution of the script)
> which are not defined (errors I do not get if I launch the script as
> usually).
Yade imports a few things automatically when it starts (into the
namespace where the script runs, and also where the command line
operates). Execfile creates a new global scope, which is initially
empty.
There are 2 solutions (or 3):
1. Look at http://docs.python.org/library/functions.html#execfile and
pass globals as the second arg, like this:
execfile('script.py',globals())
2. Import all stuff in your script explicitly, i.e. start your script
with
from yade import * ## all c++ classes, O (Omega) object
from math import * ## math functions
3. A long-term solution would be to have nothing imported automatically,
requiring all scripts to start with
from yade import * # or import yade, if you use yade.O and so on
This would be the cleanest solution and we might go in that direction in
the future pehaps.
Cheers, v
Follow ups
References