欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

第一部分day4-三次登录实验、字符编码

程序员文章站 2022-06-01 12:07:35
1 memu = { 2 "陕西":{ 3 "西安市":{ 4 "新城区":["大明宫遗址","含元殿遗址","八路军办事处"], 5 "碑林区":["安碑林博物馆","明城墙","小雁塔" ], 6 "莲湖区":["钟鼓楼","明城墙","西安都城隍庙""西安清真大寺"], 7 &qu...
#-----三次登录实验-----
 1 memu = {
 2     "陕西":{
 3         "西安市":{
 4             "新城区":["大明宫遗址","含元殿遗址","八路军办事处"],
 5             "碑林区":["安碑林博物馆","明城墙","小雁塔" ],
 6             "莲湖区":["钟鼓楼","明城墙","西安都城隍庙""西安清真大寺"],
 7             "雁塔区":["秦二世胡亥墓","大兴善寺","大雁塔","曲江池","陕西历史博物馆"],
 8             "未央区":["秦阿房宫","汉未央宫","唐大明宫"],
 9             "蓝田":["华胥故里","水陆庵","王顺山","汤峪","蓝田人遗址"]
10         },
11         "汉中市":{
12             "南郑":["红寺湖风景区","黎平国家森林公园","汉山广场"],
13             "城固":["张骞纪念馆","南沙湖风景区","桔园景区"],
14             "洋县":["开元舍利塔"],
15             "佛坪":["大坪屿风景区","佛坪县自然保护区"]
16         }
17     },
18     "重庆市":{
19         "渝中区":["解放碑","朝天门","洪崖洞","若瑟堂"],
20         "万州区":["万州大瀑布","青龙瀑布","天生城","铁峰山国家森林公园"],
21         "涪陵区":["白鹤梁","大木花谷","武陵山大裂谷","816核军工洞"],
22         "大渡口":["小南海温泉","中华美德公园","金色蛋糕梦幻王国"],
23         "江北区":["观音桥","铁山坪森林公园","金源方特科幻公园"]
24     }
25 }
 1 current_layer = memu
 2 parent_layer = []
 3 while true:
 4     for key in current_layer:
 5         print(key)
 6     choice = input(">>>:").strip()
 7     if len(choice) == 0 : continue
 8     if choice in current_layer:
 9         parent_layer.append(current_layer)
10         try:
11             if current_layer[choice]:
12                 current_layer = current_layer[choice]
13         except exception:
14             print("输入错误,请重新输入!".center(50,'-'))
15             continue
16     elif choice == 'b':
17         try:
18             if current_layer:
19                 current_layer = parent_layer.pop()
20         except exception:
21             print("已返回首页目录".center(50,'-'))
22 
23     else:
24         print("无此项目")
#-----字符编码-----

#-----中国字符编码发展-----
ascii :只能存英文和拉丁字符,一个字符占一个字符,8位
gb2312:gb 2312 标准共收录 6763 个汉字
gbk:gbk 共收入 21886 个汉字和图形符号
gb18030:gb 18030 与 gb 2312-1980 和 gbk 兼容,共收录汉字70244个

unicode:utf-32:一个字符占4个字节
unicode:utf-16:一个字符占2个字节或2个以上
unicode:utf-8:一个英文用ascii码来存储,一个中文占3个字节

#-----in python2-----
utf-8 --decode-->unicode--encode-->gbk
gbk--decode-->unicode--encode-->utf-8

#测试环境为python2,在windows 客户端(gbk编码)运行
1 a = "棒极了"
2 gbk_to_unicode = a.decode("utf-8")
3 print(a) #妫掓瀬浜
4 utf8_to_unicode = gbk_to_unicode.encode("gbk")
5 print(gbk_to_unicode) #棒极了
6 print(utf8_to_unicode)#棒极了
#-----in python3 -----
字符默认编码unicode ,文件默认编码utf-8
encode 在编码同时,会把数据转成bytes 类型
decode 在解码同时,会把数据转成字符串
b = byte = 字符类型= [0-255]