From c0fe75ef21f4deb6306964d23d05b531a13a8b70 Mon Sep 17 00:00:00 2001 From: jackfood Date: Sat, 16 Sep 2023 16:12:41 +0800 Subject: [PATCH] ~extractpython.py --- ~extractpython.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ~extractpython.py diff --git a/~extractpython.py b/~extractpython.py new file mode 100644 index 0000000..9a31fb1 --- /dev/null +++ b/~extractpython.py @@ -0,0 +1,20 @@ +# Read the AI's response from 'aianswer.txt' +with open('aianswer.txt', 'r', encoding='utf-8') as file: + ai_response = file.read() + +# Find and extract content between triple backticks (```python) and (```) +start_marker = "```python" +end_marker = "```" +start_index = ai_response.find(start_marker) +end_index = ai_response.find(end_marker, start_index + len(start_marker)) + +if start_index != -1 and end_index != -1: + python_content = ai_response[start_index + len(start_marker):end_index] + + # Save the extracted Python content to 'aipythonanswer.txt' as UTF-8 + with open('aipythonanswer.txt', 'w', encoding='utf-8') as python_file: + python_file.write(python_content) + + print("Python content extracted and saved to 'aipythonanswer.txt'") +else: + print("No Python code found between triple backticks in 'aianswer.txt'")