try:
f = open("D:/abc.txt","r",encoding="UTF-8")
except:
print("出现异常了,因为文件不存在,我将open的模式,改为w模式去打开")
try:
print(name)
except NameError as e:
print("出现了变量未定义的异常")
try:
1/0
except (NameError,ZeroDivisionError) as e:
print("出现异常")
try :
1/0
except Exception as e:
print("出现异常了")
else:
print("hahaha")
finally:
print("无论如何都会执行这行代码")
def func1():
print("func1 begin")
name =1/0
print("func1 end")
def func2():
print("func2 begin")
func1()
print("func2 end")
def main():
try:
func2()
except Exception as e:
print(f"OK")
main()
from my_modle import *
add(1,2)
min(1,2)
import my_package.my_module1
import my_package.my_module2
my_package.my_module1.info_print1()
my_package.my_module2.info_print2()
from my_package import my_module1
from my_package import my_module2
my_module1.info_print1()
my_module2.info_print2()
from my_package.my_module1 import info_print1
info_print1()
from my_package import *
my_module1.info_print1()
my_module2.info_print2()
__all__ = ['add']
def add(a,b):
print(a+b)
def min(a,b):
print("hahah")
if __name__ == '__main__':
add(1,2)
import json
data = [{"name":"rookie","age" : 18},{"name":"shy","age" : 45},{"name":"ning","age":22}]
data_str = json.dumps(data)
print(data_str)
print(type(data_str))
d = {"name":"周杰伦","age":58}
d_str = json.dumps(d,ensure_ascii=False)
print(d_str)
s = '[{"name":"rookie","age" : 18},{"name":"shy","age" : 45},{"name":"ning","age":22}]'
l = json.loads(s)
print(l)
print(type(l))
d = '{"name":"周杰伦","age":58}'
t = json.loads(d)
print(t)
print(type(t))
from pyecharts.charts import Line
from pyecharts.options import TitleOpts,LegendOpts,ToolboxOpts,VisualMapOpts
line = Line()
line.add_xaxis(["中国","美国","英国"])
line.add_yaxis("GDP",[30,20,10])
line.set_global_opts(
title_opts=TitleOpts(title="GDP展示",pos_left="center",pos_bottom="1%"),
legend_opts=LegendOpts(is_show=True),
toolbox_opts=ToolboxOpts(is_show=True),
visualmap_opts=VisualMapOpts(is_show=True)
)
line.render()