check import action in code editor
This commit is contained in:
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Binary file not shown.
@@ -2,6 +2,12 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
import subprocess
|
import subprocess
|
||||||
from streamlit_ace import st_ace
|
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):
|
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:
|
if content:
|
||||||
with open("./webpages/input_code.py", "w") as f:
|
with open("./webpages/input_code.py", "w") as f:
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
# Example 3: Demonstrating basic arithmetic operations
|
# Example 1
|
||||||
|
|
||||||
a = 10 # Assigns integer 10 to variable 'a'
|
Age = 24;
|
||||||
|
|
||||||
if Age >=18:
|
if Age >=18:
|
||||||
|
|
||||||
c = 2.5 # Assigns floating-point number 2.5 to variable 'c'
|
print('You are an adult')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print('Addition: ', a + b) # Prints the sum of 'a' and 'b'
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user