From: <Mat...@i2...> - 2002-01-31 19:37:10
|
Hi all, I have an application which embeds jython, and whenever I run a script, the __name__ variable is set to '__builtin__' by I assume the interpreter. Normally in python, modules can check the value of __name__ to selectively run code based on being run from the commandline (value of '__main__') vs being imported. Whats the best way to do this in jython? Currently what I do is shown below but I'm not sure if this is correct. The reason for my apprehension is that when I just run an interactive interpreter, I notice that sys.modules has a __main__ module, so I'm wondering if I have to create that or something else special. PythonInterpreter interp = new PythonInterpreter(); interp.set("__name__", "__main__"); interp.execfile("myscript.py"); Any help appreciated, thanks, Matt mat...@i2... |