其他代码用法 topics-code2
9. 代码块¶
9.1. bash代码样例¶
#!/bin/bash
#================================================
#FileName :test_select_46_zhaojiedi.sh
#Author :zhaojiedi
#Description:
#DateTime :2017-12-23 10:15:57
#Version :V1.0
#Other :
#================================================
select c in yes no ; do
echo " you enter is $c"
case $c in
yes)
echo "yes";;
no)
echo "no";;
*)
echo "other";;
esac
done
9.2. python代码样例¶
try:
f = open('/path/to/file', 'r')
print(f.read())
finally:
if f:
f.close()
with open('/path/to/file', 'r') as f:
print(f.read())
f = open('/Users/michael/gbk.txt', 'r', encoding='gbk', errors='ignore')
9.3. json对象样例展示¶
{
"name": "BeJson",
"url": "http://www.bejson.com",
"page": 88,
"isNonProfit": true,
"address": {
"street": "科技园路.",
"city": "江苏苏州",
"country": "中国"
},
"links": [
{
"name": "Google",
"url": "http://www.google.com"
},
{
"name": "Baidu",
"url": "http://www.baidu.com"
},
{
"name": "SoSo",
"url": "http://www.SoSo.com"
}
]
}