Closed qiang437587687 closed 6 years ago
If the return value is the value you want to display on the console, you can use NSLog
:
NSLog(@"The result was: %d\n", ret)
OK, first thanks for review my request. Did not say clearly, it is my fault..
I want receive python file print message here, just like:
PyObject *pyObject = PyRun_xxxxxFile(fd, main_script);.
NSString *str = pyObject.string()
UIAlertView *al = [[UIAlertView alloc] init];
al.title = str;
al.frame = ...
[al show];
Or the python.framework could works like python interpreter ? Thank you.
If I'm understanding you correctly, you need to take a look at Rubicon. Rubicon is a bridge between Python and the Objective C runtime, so you can call Objective C methods from inside Python. The sample code you provide here would be achieved with something like:
from rubicon.objc import *
UIAlertView = ObjCClass('UIAlertView')
al = UIAlertView.alloc().init()
al.title = "your title here"
al.frame = "Your content here"
al.show()
(I haven't tested this specific code snippet, but it should be something very similar to this)
We've recently added improved log handling on the iOS template; using the most recent template, anything output to stdout or stderr (with print()
) will be written to the system log.
I created the project correctly and run it... but question is how to receive the log message in my code.
const char* main_script = [[[NSBundle mainBundle] pathForResource:@"Library/ApplicationSupport/zhangPythonBundle.zhangpython/app/zhangpython/app" ofType:@"py"] cStringUsingEncoding:NSUTF8StringEncoding];
FILE* fd = fopen(main_script, "r");
ret = PyRun_AnyFile(fd, main_script);
You know, this code return an int number ‘ret’, Xcode logs python file message, but I want use a NSString to receive execute result. Is there a method or API could use to solve my question?
Thank a lot.