473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Jython: preload PythonInterpreter with values for use in scripts

How can I set variables in PythonInterpreter such that
scripts then run via import can have access to it.

My idea was to go along the lines of:

PythonInterpreter ip = new PythonInterpreter();
// make the object about to use the interpreter
// available to that interpreter
ip.set("javaCaller", this);
ip.exec("import mystuff");

Within mystuff.py I wanted to do things like

m = sys.modules['__main__']
m.javaCaller.setThoseNiftyFeaturesOfTheCallingJava Object("hello")

Alas, sys.modules does not contain '__main__'.

Is there any way to get hold of locals() of PythonInterpreter ip within
a module imported as shown above?

I would expect that execfile allows the above communication,
but then I have to do all the searching for the module myself.
Therefore a solution where the module is simply imported as above
is preferred.

Thanks,
Harald.
Jul 18 '05 #1
0 1415

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ProgDario | last post by:
Hello, in the site I found a lot of complicated examples, but I can't find the simple one I'm looking for. The problem is: I have 1 jython file (script1.py) with a function named...
4
by: Michael Chermside | last post by:
Ype writes: > For the namespaces in Jython this 'Python internal thread safety' > is handled by the Java class: > > http://www.jython.org/docs/javadoc/org/python/core/PyStringMap.html > > which...
1
by: Mike Grigorov | last post by:
I am using cheetah with jython 2.1 and I have problem generating templates that contain cyrillic text. Some texts are printed OK and others are not. I searched Jython and cheetah projects mailing...
0
by: Ike | last post by:
I have a signed JApplet which has a JTextArea wherein one can put Jython Script. Upon clicking a JButton, the script is executed. The script which executes to code is listed below. If I run the...
2
by: pythonUser_07 | last post by:
Is this the correct place to post a jython question? I posted the following in the jython group, but I figured I'd post here too: _________________________________________ I am assuming that...
7
by: Jan Gregor | last post by:
Hello folks I want to apply changes in my source code without stopping jython and JVM. Preferable are modifications directly to instances of classes. My application is a desktop app using swing...
12
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
1
by: techwiz18 | last post by:
Hello, I'm trying to execute a Python script from a Java class using Jython. I'm running into the following error: Exception in thread "main" Traceback (innermost last): File "<string>",...
1
by: nmin | last post by:
Hi. I'm using Jython in combination with Java, webservices and jboss4.0.4. The webservice is implemented in java and creates an PythonInterpreter object which loads the jython scripts. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.