From: Ype K. <yk...@xs...> - 2002-01-10 19:35:19
|
>In a Jython script, I import a Java class with: > > from jp import * > >unfortunately, inside "jp" is a method named "abs" which takes one >argument of a highly specialized type (non-python). After this import, if >I try to do: > >abs(3) > >I get an error that the argument could not be coerced to the "specialized >type" required by the "jp.abs()" method. > >While there are "workarounds" for this (like an explicit "from jp import >x,y,z"), I'd like to know if there is anything else I can do so that >script-writers won't inadvertantly run into this. > >I have spoken with the own of the library that "jp" is contained in about >simply changing the method names, but any other suggestions would be >welcomed. Write a wrapper module jpwrap.py: from jp import * jpabs = abs del abs and import this as: from jpwrap import * >Thanks. My pleasure. However, it is considered bad style to use from ... import * outside an interactive session. Explicit is better than implicit. This works also: import jp jp.abs(someArgWithSpecializedType) When your module name is very long, use eg.: import moduleWithLongName as lNamMod When the dot operator gets too expensive replace it by a local variable in the loop. Good luck, Ype -- |