|
From: Charlie G. <cha...@gm...> - 2009-08-13 21:26:34
|
2009/8/12 Darius Kučinskas <d.k...@gm...>: > Hi, > > I am writing jython application with eclipse SWT/JFace. I have to pass float > array to java object to get back some values from it. I am using jarray > package for it. Is there more pythonic way to do it? > > --->8 code 8<--- > bounds = zeros(4, 'f') > > > # from java org.eclipse.swt.graphics.Path.getBounds(float[] bounds) > path.getBounds(bounds) Jython should convert python lists to Java arrays, so I think you can do path.getBounds([0.0, 0.0, 0.0, 0.0]) > # from java org.eclipse.swt.graphics.Rectangle(int x, int y, int width,int > height) > rect = Rectangle(int(round(bounds[0])), > > > int(round(bounds[1])), > > > int(round(bounds[2])), > > > int(round(bounds[3]))) You can combine Frank's list comprehension with an * to explode the arguments to make this rect = Rectangle(*[int(round(x)) for x in bounds]) Charlie |