40 lines
926 B
Python
40 lines
926 B
Python
# hello_world_advanced.py
|
|
"""
|
|
Hello World 程序 - Python 3.12
|
|
演示基本语法和新特性
|
|
"""
|
|
import torch
|
|
import insightface
|
|
import cv2
|
|
|
|
def main():
|
|
# 基础输出
|
|
print("Hello, World!")
|
|
|
|
print("InsightFace版本:", insightface.__version__)
|
|
|
|
# 使用f-string (Python 3.6+)
|
|
version = "3.12"
|
|
print(f"Running on Python {version}!")
|
|
|
|
# 演示Python 3.12的改进错误信息
|
|
try:
|
|
# 这里故意创建一个错误来看改进的错误信息
|
|
x = "hello"
|
|
y = x + 1 # 这会触发TypeError
|
|
except TypeError as e:
|
|
print(f"Error demo: {e}")
|
|
|
|
# 使用match语句 (Python 3.10+)
|
|
language = "Python"
|
|
match language:
|
|
case "Python":
|
|
print("You're using Python! 🐍")
|
|
case "Java":
|
|
print("You're using Java!")
|
|
case _:
|
|
print("You're using another language")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |