check import action in code editor

This commit is contained in:
BuffTechTalk
2024-09-12 07:31:31 -05:00
parent 22015e4964
commit e738379dbe
4 changed files with 18 additions and 11 deletions

Binary file not shown.

View File

@@ -2,6 +2,12 @@
import streamlit as st
import subprocess
from streamlit_ace import st_ace
import re
# check if user import python module
def analyze_imports(code):
pattern = r'^\s*(from\s+\S+\s+)?import\s+(\S+)(\s+as\s+\S+)?'
return re.findall(pattern, code, re.MULTILINE)
def code_editor(height="300px", sample_code = "", editor_label = "",min_lines = 20):
@@ -26,6 +32,9 @@ def code_editor(height="300px", sample_code = "", editor_label = "",min_lines =
)
if analyze_imports(content):
st.warning("Code Editor does not support importing packages")
return
if content:
with open("./webpages/input_code.py", "w") as f:

View File

@@ -1,12 +1,10 @@
# Example 3: Demonstrating basic arithmetic operations
a = 10 # Assigns integer 10 to variable 'a'
# Example 1
Age = 24;
if Age >=18:
c = 2.5 # Assigns floating-point number 2.5 to variable 'c'
print('Addition: ', a + b) # Prints the sum of 'a' and 'b'
print('You are an adult')