FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Tools
(Moderator: REAS)
   Python inside P5
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Python inside P5  (Read 2405 times)
gll

WWW Email
Python inside P5
« on: Dec 12th, 2004, 6:52am »

I was looking for a way to play with the files on my local machine, something between P5 and my system.
I tried something with Python/Jython.
 
I'm using Eclipse where I imported external jars comm.jar, pde.jar, jython.jar. It works well.
Maybe it'll be a great idea to put it in P5.
 
Here's a simple example.
 
[1]-Create a new project in Eclipse
[2]-Import comm.jar + pde.jar + jython.jar (jython.jar is found inside C:\Prog\jython\)
 
 
Code:
import org.python.util.PythonInterpreter;
import org.python.core.*;
 
public class myPy extends BApplet {  
   
 void setup() {  
  size(200, 200);  
  //setup
  py();
 }  
 
 void loop() {  
  background(255);  
  //loop
 }  
 
 void py() {
    PythonInterpreter interp = new PythonInterpreter();
     
    //Default jython example
    System.out.println("Hello, brave new world");
    interp.exec("import sys");
    interp.exec("print sys");
 
    interp.set("a", new PyInteger(42));
    interp.exec("print a");
    interp.exec("x = 2+2");
    PyObject x = interp.get("x");
 
    System.out.println("x: "+x);
    System.out.println("Goodbye, cruel world");
 }
}
 

guillaume LaBelle
REAS


WWW
Re: Python inside P5
« Reply #1 on: Dec 15th, 2004, 9:58am »

Yes, this is something that will be easy for people to sew together when we are able to release the source.
 
Casey
 
 
Pages: 1 

« Previous topic | Next topic »