-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (25 loc) · 744 Bytes
/
utils.py
File metadata and controls
30 lines (25 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st
def try_parse_int(value) -> int:
"""
Try to parse the input value as an integer.
Parameters:
value (any): The value to attempt to parse as an integer.
Returns:
int or None: If successful, returns the parsed integer value. If parsing fails,
returns None.
Example:
>>> try_parse_int("123")
123
>>> try_parse_int("abc")
None
"""
try:
return int(value)
except:
return None
def check_if_key_is_in_session_state(key: str):
"""
Sanity check for making sure that the `key` provided is in StreamLit's session state.
"""
if key not in st.session_state:
st.session_state[key] = None