is it possible to store the output of a .py file in a swift variable? In my xcode project I have put a python script. I run this script using this code
class ViewController: NSViewController {
var pathForFile = Bundle.main.path(forResource: "eject", ofType: "py")
let path = "/usr/bin/python/"
override func viewDidLoad() {
let arguments = [pathForFile]
let task = Process.launchedProcess(launchPath: path, arguments: arguments as! [String])
task.waitUntilExit()
super.viewDidLoad()
}
}
If I put print(x)
in the python file, once executed I can see the x value on the output window of xcode.
I also tried to put return x
in the main function and then tried to set let y = task.waitUntilExit()
in the swift file, but the only thing I get is an empty variable
I don't know much about swift, so please forgive my lack of knowledge. Thanks in advance!