We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I'm currently reading the book "Getting Started with Processing" without using Java but Python instead and I'm trying to figure how to convert this piece of code into Python.
Table stats;
void setup() {
stats = loadTable("ortiz.csv");
for (int i = 0; i < stats.getRowCount(); i++) {
// Gets an integer from row i, column 0 in the file
int year = stats.getInt(i, 0);
// Gets the integer from row i, column 1
int homeRuns = stats.getInt(i, 1);
int rbi = stats.getInt(i, 2);
// Read a number that includes decimal points
float average = stats.getFloat(i, 3);
println(year, homeRuns, rbi, average);
}
}
I've tried a way with importing the csv module and playing with that but I'm not sure that it's the same way as the book deal with.
Any help would be very appreciated! (Sorry for my skilless english) Thanks!
Answers
Disclaimer: I just know Python by quick glances. Almost none! ~O)
"Python Mode" is implemented in Jython: https://en.Wikipedia.org/wiki/Jython
And it has full access to Java libraries + Processing framework: http://py.Processing.org/
Therefore there's no need to look for Python libraries which are already present in "Python Mode".
Even barely knowing any Python I was able to convert your "Java Mode" sketch to "Python Mode": :>
It worked perfectly, many thanks for your help!
A more comfy & clean way is to iterate over rows() in order to get each TableRow from Table: *-:)
https://Processing.org/reference/Table_rows_.html
https://Processing.org/reference/TableRow.html
Yes much better way, thanks again!
Name Error: Pshader is not defined. while converting java code to python
in Java: PShader sh;
In python: sh=PShader()
@Prabhnith, just found out today, after converting a Java Mode sketch to Python Mode, that the latter doesn't seem to automatically
import
anything outside PApplet class! @-)https://forum.Processing.org/two/discussion/comment/61895/#Comment_61895
And even many PApplet methods are missing as well.
For example I had to
import
dataPath():from processing.core.PApplet import dataPath
And even worse, I had to pass this as an extra 1st argument for it to work: 3:-O
path = dataPath(this, xml.getName() + '.xml')
It's true dataPath() doesn't belong to the "official" Processing API.
However I've found out that thread(""), which is listed in the API reference, got the same issue:
https://Processing.org/reference/thread_.html
I don't think any regular Python mode user gonna find out those import paths so easily.
It's nowhere to be found in any regular reference. It's simply expected to just work w/o any imports! =;
I wonder if all of that's unintended or it's an official stand for Processing.py? :|
@Prabhnith, I've just explained the situation but forgot to search for the solution! 8-}
Class PShader belongs to
package
processing.opengl; therefore:Although its reference page strongly encourages loadShader() instead.
Which in turn doesn't warrant any
from ... import ...
in order to be accessed at all: ;)https://Processing.org/reference/PShader.html
https://Processing.org/reference/loadShader_.html
thankyou sir :)
sir in this code there is no error but it is not showing the correct output. Please review this code @GoToLoop https://github.com/jdf/processing.py/pull/183/files
It is the converted example of the java mode. (Rotating Arcs)
original java file https://github.com/processing/processing-docs/blob/master/content/examples/Demos/Graphics/RotatingArcs/RotatingArcs.pde
Trying to clean up the code before attempting to convert it to Python mode: #:-S
Watch it online: http://studio.ProcessingTogether.com/sp/pad/export/ro.9AqEIV-5Q9sCx
i think i should do the shorter examples first before going too further. :/
Finally Python Mode version is here. <:-P Although it's at least 30% slower: :o3
@Prabhnith, I've adapted the "Wiggling Cube" example from:
https://GitHub.com/processing/processing-docs/blob/master/content/examples/Demos/Graphics/Wiggling/Wiggling.pde
For your pull request here: https://GitHub.com/jdf/processing.py/pull/182
Below Java Mode's tweaked version: :ar!
And finally the Python Mode version: :bz
Anything in the official Processing reference is meant to also be supported in Python Mode. If it isn't, that's a bug. Please file a bug: https://github.com/jdf/Processing.py-Bugs/issues