beeware / Python-Apple-support

A meta-package for building a version of Python that can be embedded into a macOS, iOS, tvOS or watchOS project.
MIT License
1.11k stars 160 forks source link

ios #104

Closed h242799999 closed 3 years ago

h242799999 commented 3 years ago

I want to be a python compiler. I hope to get the result after running. Py file.

For example, python print ("sssssss") I want to get the printed results

dgelessus commented 3 years ago

To capture the output of your Python code, you can replace sys.stdout with an io.StringIO before you run the code that prints something, and then read out the contents of the StringIO afterwards.

As @freakboy3742 said in #103, it would really help if you could explain a bit more what you're trying to do exactly. Are you writing an app in Python and want to use print for debugging? Or do you want to show a message to the user?

h242799999 commented 3 years ago

To capture the output of your Python code, you can replace sys.stdout with an io.StringIO before you run the code that prints something, and then read out the contents of the StringIO afterwards.

As @freakboy3742 said in #103, it would really help if you could explain a bit more what you're trying to do exactly. Are you writing an app in Python and want to use print for debugging? Or do you want to show a message to the user?

I want to be a python compiler for iPad. I hope to compile Python code on iPad, which is similar to 'pythonista'. We do K12 programming education

  1. Python compilation

  2. Python console

freakboy3742 commented 3 years ago

@h242799999 This repository won't assist you with any of pieces of putting GUI elements on the screen of your tablet. It only contains the core Python engine. You then need to build the GUI for that app, take text from the GUI widgets, run it through the Python core, and display any output from the Python code on your GUI.

In summary - If you want an app like Pythonista, then you're going to need to build an app like Pythonista. Python-Apple-support will only help you run the Python code. Everything else is up to you.

As for how to get the input/output of specific Python code - you need to use the Python embedded APIs to control how you invoke Python files or modules. Advising how to use those APIs is outside the scope of the help we're able to provide.

Closing this ticket since the question should now be answered. If you need more details or clarification, feel free to continue the conversation here.

h242799999 commented 3 years ago

@h242799999 This repository won't assist you with any of pieces of putting GUI elements on the screen of your tablet. It only contains the core Python engine. You then need to build the GUI for that app, take text from the GUI widgets, run it through the Python core, and display any output from the Python code on your GUI.

In summary - If you want an app like Pythonista, then you're going to need to build an app like Pythonista. Python-Apple-support will only help you run the Python code. Everything else is up to you.

As for how to get the input/output of specific Python code - you need to use the Python embedded APIs to control how you invoke Python files or modules. Advising how to use those APIs is outside the scope of the help we're able to provide.

Closing this ticket since the question should now be answered. If you need more details or clarification, feel free to continue the conversation here.

Thank you very much.