Re: Transferring data between Python and Cocoa (maybe a newbie question)
Re: Transferring data between Python and Cocoa (maybe a newbie question)
- Subject: Re: Transferring data between Python and Cocoa (maybe a newbie question)
- From: "Ritesh Nadhani" <email@hidden>
- Date: Wed, 6 Feb 2008 09:57:31 -0600
Hey
2008/2/6 Nir Soffer <email@hidden>:
>
>
> On Feb 6, 2008, at 00:51, Ritesh Nadhani wrote:
>
> Hello
>
> So I started developing my first real life Cocoa app as part of my school
> work.
>
> My app needs to connect to various servers to fetch similar data. The
> issue is that the servers might use different way to get data. Some
> use XML-RPC (majority of them are RPC), some use client-server etc.
> User can add more server by adding a plugin. We already have bunch of
> python scripts that just do that.
> [....]
> You can add the needed parts from PyObjC to your app, the user will not have
> to install anything. py2app will do this automatically for you.
>
As I read from the docs, py2app will take a bunch of python files and
make an app out of it. My project is in Cocoa completely. Its just
this option that I need tohave in Python.
>
> Other option would be to output the data as XML from Python and parse
> it back in Cocoa and build a dictionary out of it.
>
> It the data contains only standard types, you can return the data in plist
> format:
>
>
> >>> import plistlib, StringIO
> >>> xmlrpc_result = {'a': 1, 'b': 42}
> >>> plist = StringIO.StringIO()
> >>> plistlib.writePlist(xmlrpc_result, plist)
> >>> plist.getvalue()
> '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple
> Computer//DTD PLIST 1.0//EN"
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist
> version="1.0">\n<dict>\n\t<key>a</key>\n\t<integer>1</integer>\n\t<key>b</key>\n\t<integer>42</integer>\n</dict>\n</plist>\n'
>
>
Yes, the data are in standard format. Its either strings or numbers. I
think I will use this way.
Now back to reading documents on how to convert plist to Cocoa dictionary :)
>
> Are these the only two options or there are other ways to do it? What
> do you people suggest.
> You can use WebServiceCore to do the rpc work directly in your app instead
> of using Python.
>
> You can use AppleScript to do the rpc work, and run it with NSAppleScript.
> But I would not recommend it because AppleScript must run the main thread
> and you want to do rpc in a background thread.
>
>
>
>
> Best Regards,
>
>
>
>
> Nir Soffer
>
--
Ritesh
http://www.riteshn.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden