Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:55:41+00:00 2026-06-10T00:55:41+00:00

My application uses NSTask to start a Python script, then the script returns an

  • 0

My application uses NSTask to start a Python script, then the script returns an array via NSPipe. I read the data, stick it in a string, and display it:

NSMutableData *data = [[NSMutableData alloc] init];
NSData *readData;

while ((readData = [readHandle availableData])&& [readData length]) {
    [data appendData: readData];
}


NSString *string = [[NSString alloc] 
                    initWithData: data 
                    encoding: NSUTF8StringEncoding];

That’s all fine, but I realized I really need to keep it as an array – not a string. I can’t find a method that initiates array from data (data returned from NSPipe). How can I do that? The closest thing I found is possibly using:

[NSPropertyListSerialization dataWithPropertyList:format:options:error:]

… but I don’t need a “property list” per se. Do I have to convert the data to plist first?

EDITED: I just realized it’s more complicated than I thought. Python returns an array of dictionaries, in the dictionary there are strings. These strings can have commas and other chars, so I don’t think I can use a “,” separator to break it up.

in Python:

msg_set = []
msg_set = [
   dict(mts="t,s1", mfrom="f@ro,m1", msbj="msb,j1", mbody="bod,y1", mid="i,d1"),
   dict(mts="ts2", mfrom="from2", msbj="msb,j2", mbody="body2", mid="id2")
]
print msg_set # <- this is what python returns
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:55:42+00:00Added an answer on June 10, 2026 at 12:55 am

    You can convert the data to JSON first (I saw the comments on dasblinkenlight’s answer but I had already typed my answer) and then pass them to Cocoa. Something like this:

    Python Side

    import json
    #...
    json.dumps(msg_set) # <- return this one instead
    

    Objective-C Side

    NSString *myPythonJson = @""; // <- Whatever you got from python
    NSError *error = nil;
    id myObjectsFromJson = [NSJSONSerialization JSONObjectWithData:[myPythonJson dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application uses the PersistentStore to store data. The keys of the PersistentStore are
My application uses rich:calendars and h:inputText. If I put input bad data in the
Our application uses Hibernate for ORM, and stores data in several schemas, accessing them
Our application uses an SQLite database file to hold some data in it. The
my application uses the standard app.config to store the public configuration data. However, there
My application uses a data directory on the SD card to store files. At
my application uses libjpeg to read/write JPEG-images. everything worked fine recently my app started
application uses codeigniter and tank_auth with it. I need to add some more data
My application uses a MapView which will display multiple places. I have the latitude
My application uses a 3rd party dll. If I remove myapp.exe.local file from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.