简体   繁体   English

移动应用程序如何与 python 脚本交互?

[英]How does a mobile app interact with a python script?

I have no idea how one might "connect" backend to front end and where you may store/host each entity.我不知道如何将后端“连接”到前端以及您可以在哪里存储/托管每个实体。

Say I have a python script/program that has various functions that when called return certain information (currently working in the terminal) and I want to display said information on a native iOS or Android app.假设我有一个 python 脚本/程序,该脚本/程序具有各种功能,在调用时会返回某些信息(当前在终端中工作),并且我想在本机 iOS 或 Android 应用程序上显示所述信息。 The python script manipulates data and outputs pandas data frames and other text and numeric information. python 脚本操作数据并输出 pandas 数据帧和其他文本和数字信息。

Once the shell of the app has been build etc, how would one go about making a button on the app call a function from a python script for example? Once the shell of the app has been build etc, how would one go about making a button on the app call a function from a python script for example?

I currently imagine that both entities would be hosted separately, say the python code on AWS, and the app makes a request to the server for a particular function (no idea how?) and the python script sends a response (in what form? JSON?) and the app code interprets it and displays it... Hope this isn't to vague but I've no experience with apps or hosting code etc... I currently imagine that both entities would be hosted separately, say the python code on AWS, and the app makes a request to the server for a particular function (no idea how?) and the python script sends a response (in what form? JSON ?)并且应用程序代码对其进行解释并显示它......希望这不是含糊的,但我没有应用程序或托管代码等方面的经验......

I suggest putting your Python code into an AWS Lambda function, and exposing it as an HTTP API via Amazon API Gateway. I suggest putting your Python code into an AWS Lambda function, and exposing it as an HTTP API via Amazon API Gateway.

Next, you'll create a simple Android app in Kotlin with Android Studio.接下来,您将使用 Android Studio 在 Kotlin 中创建一个简单的 Android 应用程序。 Your Android app will call the HTTP API to get results from the Python script (the Python script is running in AWS.) Your Android app will call the HTTP API to get results from the Python script (the Python script is running in AWS.)

You can used AWS' Amplify Android project to automate most of this.您可以使用 AWS 的 Amplify Android 项目来自动完成大部分工作。 The documentation below will guide you to create simple Lambda function, and to bootstrap the communication from an Android project.下面的文档将指导您创建简单的 Lambda function,并从 Android 项目引导通信。 Once you have the Lambda, update it so that it invokes your Python code.获得 Lambda 后,对其进行更新,以便它调用您的 Python 代码。

https://docs.amplify.aws/lib/restapi/getting-started/q/platform/android https://docs.amplify.aws/lib/restapi/getting-started/q/platform/android

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM