timmy revisou este gist 10 months ago. Ir para a revisão
Sem alterações
timmy revisou este gist 10 months ago. Ir para a revisão
Sem alterações
timmy revisou este gist 10 months ago. Ir para a revisão
Sem alterações
timmy revisou este gist 10 months ago. Ir para a revisão
1 file changed, 33 insertions
python_version_checker.py(arquivo criado)
| @@ -0,0 +1,33 @@ | |||
| 1 | + | import sys | |
| 2 | + | ||
| 3 | + | class PythonVersionChecker: | |
| 4 | + | def __init__(self, supported_versions): | |
| 5 | + | self.supported_versions = supported_versions | |
| 6 | + | ||
| 7 | + | def get_current_version(self): | |
| 8 | + | """取得當前的 Python 版本。""" | |
| 9 | + | return sys.version_info[:2] | |
| 10 | + | ||
| 11 | + | def is_supported(self): | |
| 12 | + | """檢查當前的 Python 版本是否在支援的版本列表中。""" | |
| 13 | + | current_version = self.get_current_version() | |
| 14 | + | return current_version in self.supported_versions | |
| 15 | + | ||
| 16 | + | class StreamlitVersionChecker(PythonVersionChecker): | |
| 17 | + | def __init__(self): | |
| 18 | + | # 定義 Streamlit 支援的 Python 版本 | |
| 19 | + | supported_versions = [(3, 9), (3, 10), (3, 11), (3, 12), (3, 13)] | |
| 20 | + | super().__init__(supported_versions) | |
| 21 | + | ||
| 22 | + | def check_version(self): | |
| 23 | + | """檢查並輸出當前的 Python 版本是否受 Streamlit 支援。""" | |
| 24 | + | current_version = self.get_current_version() | |
| 25 | + | if self.is_supported(): | |
| 26 | + | print(f"當前的 Python 版本 {current_version[0]}.{current_version[1]} 受 Streamlit 支援。") | |
| 27 | + | else: | |
| 28 | + | print(f"當前的 Python 版本 {current_version[0]}.{current_version[1]} 不受 Streamlit 支援。") | |
| 29 | + | ||
| 30 | + | # 使用範例 | |
| 31 | + | checker = StreamlitVersionChecker() | |
| 32 | + | checker.check_version() | |
| 33 | + | ||
Próximo
Anterior