简体   繁体   中英

How can I run a Python script from within a React Native app?

I want to run a this Python script:

import socket

def isConnected():
    try:
        # connect to the host -- tells us if the host is actually
        # reachable
        sock = socket.create_connection(("www.google.com", 80))
        if sock is not None:
            print('OK')
            sock.close
        return True
    except OSError:
        pass
    return False

inside a brand new React Native app for testing purposes.

I'm working inside a team and somebody else is handling the real Python code for the project. They asked me whether I'll be able to run their Python scripts from within my React Native app and I wasn't sure if it was possible, so that's why I'm posting my question here.

Note: My React Native app is initialized with react-native cli and not expo .

Please provide a detailed answer as I'm a newbie when it comes to Python and any AWS features.

The easiest way would probably be to make a REST API using something like Flask and then send HTTP requests from React Native to your API.

If you are new to Flask and REST APIs, I would suggest checking this video out.

Flask Homepage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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