[Pyobjc-dev] [Slightly OT] jython com.apple.cocoa vs. cpython pyobjc [was: Why syntax?]
Brought to you by:
ronaldoussoren
|
From: Steven D. M. <sd...@mi...> - 2001-04-13 17:13:40
|
Since I brought up jython cocoa access vs. pyobjc:
Both bridges do:
[1] some automatic conversion to and from equivalent types, for
example, python and java strings or python strings and NSStrings.
[2] automatic mapping of equivalent protocols or interfaces, for
example, in pyobjc, NSArray instances returned from objc methods
can be treated like python sequences, for example:
>>> allbundles = runtime.NSBundle.allBundles()
>>> print allbundles[0]
>>> for x in allbundles: print x
However, in jython to Cocoa access, there are two bridges: Python
to Java and Java to Objective-C, so you don't always get the
benefit of automatic conversion or mapping. for example:
Jython 2.1a1 on java1.3.0 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> from com.apple.cocoa.foundation import *
>>> for x in NSBundle.allFrameworks(): print x
...
Traceback (innermost last):
File "<console>", line 1, in ?
AttributeError: __getitem__
# You need to get an objectEnumerator to do the equiv:
>>> for x in NSBundle.allFrameworks().objectEnumerator(): print x
...
NSBundle </System/Library/Frameworks/Foundation.framework> (loaded)
NSBundle </System/Library/Frameworks/JavaVM.framework> (loaded)
NSBundle </usr/lib/java> (loaded)
NSBundle </usr/lib> (loaded)
>>>
-- Steve Majewski
|