Call Python code from an existing project written in Swift

前端 未结 4 990
忘了有多久
忘了有多久 2020-11-27 17:26

I need a way to call Python code from Swift on an Apple platform. A library would be ideal. I\'ve done a considerable amount of Google searching, and the closest material I

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 18:06

    In swift 5 you can try PythonKit framework.

    Here's example of the usage:

    import PythonKit
    
    let sys = try Python.import("sys")
    
    print("Python \(sys.version_info.major).\(sys.version_info.minor)")
    print("Python Version: \(sys.version)")
    print("Python Encoding: \(sys.getdefaultencoding().upper())")
    

提交回复
热议问题