From: <wer...@gm...> - 2007-08-06 19:57:57
|
Hello Peke, I hope I understood your problem correctly. How about: from java.lang import String my_javatype=type(String) [...] if object_to_be_tested is my_javatype: foo foo Hope this works;at the moment I can´t try it out... Kind regards Markus -------- Original-Nachricht -------- Datum: Thu, 2 Aug 2007 02:19:11 +0300 Von: "Pekka Laukkanen" <pe...@ik...> An: "jython users" <jyt...@li...> Betreff: [Jython-users] How to test is an object a Java class? > Hello, > > In my code I'd like to test is an imported thing a module, Python > class or Java class. Testing for the two former is easy using > types.ModuleType and types.ClassType, respectively, but the latter is > more problematic. As the code below demonstrates there seems to be > separate JavaClass type but that's not available in types. > > >>> import types > >>> import os.path > >>> from java.lang import String > >>> class C: pass > ... > >>> type(os.path) > <type 'module'> > >>> type(C) > <type 'class'> > >>> type(String) > <type 'javaclass'> > >>> type(os.path) is types.ModuleType > 1 > >>> type(C) is types.ClassType > 1 > >>> type(String) is types.ClassType > 0 > >>> dir(types) > ['ArrayType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', > 'CodeType', 'ComplexType', 'DictProxyType', 'DictType', > 'DictionaryType', 'EllipsisType', 'FileType', 'FloatType', > 'FrameType', 'FunctionType', 'GeneratorType', 'InstanceType', > 'IntType', 'LambdaType', 'ListType', 'LongType', 'MethodType', > 'ModuleType', 'NoneType', 'ObjectType', 'SliceType', 'StringType', > 'StringTypes', 'TracebackType', 'TupleType', 'TypeType', > 'UnboundMethodType', 'UnicodeType', 'XRangeType', '__doc__', > 'classDictInit'] > > > What's the recommended way to test do I have a Java class or not? > Additionally, should types actually contain JavaClassType? Adding > Jython specific stuff there ought to be ok since ArrayType is there > already. Should I submit a bug/feature request about adding > JavaClassType? > > Cheers, > .peke > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users -- GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS. Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail |