一鼓作气 博客--第八篇 note8
2024-08-22 06:30:31
0、,222]
list[33]
except IndexError as e :
print('index error ')
except ValueError as e :
print('value error ')
except Exception as e :
print('error ')
print(e)
else:
print('ok')
finally:
print('final ')
6、主动触发异常
# 主动触发异常
def execute():
try:
result = foo1()
if result:
pass
else:
raise Exception('wrong way....')
foo2()
except Exception as e:
print(e)
hasattr(容器,‘名称’) # 以字符串的形式判断[某个对象]中是否含有指定的属性
server:
import socket
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind(('0.0.0.0',8000))\
server.listen(10)
print('-----Get Ready to Transfer----')
conn,c_addr=server.accept()
file_list=['serverfile']
client:
import socket
client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(('127.0.0.1',8001))
while True:
data = input('请输入上传文件,格式如get file1 or put file1')
1、绝对路径
os.path.abspath("文件名"):
显示的是一个文件的绝对路劲
eg:
1
2
3
4
5
6
|
>>> import os >>> os.chdir( "E:\\PycharmProjects\\odycmdb\\odycmdb" ) >>> os.listdir() [ 'settings.py' , 'urls.py' , 'wsgi.py' , '__init__.py' , '__pycache__' ] >>> os.path.abspath( "settings.py" ) 'E:\\PycharmProjects\\odycmdb\\odycmdb\\settings.py' |
2、相对路径
os.path.dirname("文件名"):
显示的是一个文件的相对路径
eg:
1
2
3
4
5
6
|
>>> import os >>> os.chdir( "E:\\PycharmProjects\\odycmdb\\odycmdb" ) >>> os.listdir() [ 'settings.py' , 'urls.py' , 'wsgi.py' , '__init__.py' , '__pycache__' ] >>> os.path.dirname( "settings.py" ) '' |
3、总结
一般情况下,绝对路劲函数和相对路径函数是结合起来用的,特别是在多个文件包之前相互导入
①os.path.dirname(os.path.abspath("文件名")): 表示获取当前文件夹的所在的目录
eg:
1
2
3
4
5
6
7
8
|
>>> import os >>> os.chdir( "E:\\PycharmProjects\\odycmdb\\odycmdb" ) >>> os.listdir() [ 'settings.py' , 'urls.py' , 'wsgi.py' , '__init__.py' , '__pycache__' ] >>> os.path.abspath( "settings.py" ) 'E:\\PycharmProjects\\odycmdb\\odycmdb\\settings.py' >>> os.path.dirname(os.path.abspath( "settings.py" )) 'E:\\PycharmProjects\\odycmdb\\odycmdb' |
②os.path.dirname(os.path.dirname(os.path.abspath("文件名"))): 表示获取当前文件夹上一层目录
eg:
1
2
3
4
5
6
7
8
|
>>> import os >>> os.chdir( "E:\\PycharmProjects\\odycmdb\\odycmdb" ) >>> os.listdir() [ 'settings.py' , 'urls.py' , 'wsgi.py' , '__init__.py' , '__pycache__' ] >>> os.path.abspath( "settings.py" ) 'E:\\PycharmProjects\\odycmdb\\odycmdb\\settings.py' >>> os.path.dirname(os.path.dirname(os.path.abspath( "settings.py" ))) 'E:\\PycharmProjects\\odycmdb' |
最新文章
- JQuery好用的日期选择控件 DatePicker
- .NET设计模式(3):抽象工厂模式(Abstract Factory)
- java随机数生成(固定位数)
- 不要在精确计算中使用float和double类型
- Angular过滤器 自定义及使用方法
- C# 实现文件夹的复制以及删除
- win7 64位系统装oracle11 提示环境变量path 值超过1023字符
- asp.mvc中的vue分页实例,分页组件无法重置reload,解决点击查询按钮后,分页不刷新的问题
- IPerf——网络测试工具介绍与源码解析(2)
- windows刷新本机DNS缓存
- Codeforces 765F Souvenirs 线段树 + 主席树 (看题解)
- Dockerfile文件详解
- jquery常用指令
- linux2.6.30.4内核移植(2)——Nand Flash驱动移植
- 【CF809D】Hitchhiking in the Baltic States Splay
- fafu 1413
- linux 监控文件变化
- oracle的乐观锁和悲观锁
- iOS之Custom UIViewController Transition
- P3916 图的遍历