| 这篇文章主要是针对这两天学习python的一些知识点整理 1.os相关参数学习 os库常用子函数使用 os.sep:取代操作系统特定的路径分隔符
 os.name:指示你正在使用的工作平台。比如对于Windows,它是'nt',而对于Linux/Unix用户,它是'posix'。
 os.getcwd:得到当前工作目录,即当前python脚本工作的目录路径。
 os.getenv()和os.putenv:分别用来读取和设置环境变量
 os.listdir():返回指定目录下的所有文件和目录名
 os.remove(file):删除一个文件
 os.stat(file):获得文件属性
 os.chmod(file):修改文件权限和时间戳
 os.mkdir(name):创建目录
 os.rmdir(name):删除目录
 os.removedirs(r“c:\python”):删除多个目录
 os.system():运行shell命令
 os.exit():终止当前进程
 os.linesep:给出当前平台的行终止符。例如,Windows使用'\r\n',Linux使用'\n'而Mac使用'\r'
 os.path.split():返回一个路径的目录名和文件名
 os.path.isfile()和os.path.isdir()分别检验给出的路径是一个目录还是文件
 os.path.existe():检验给出的路径是否真的存在
 os.listdir(dirname):列出dirname下的目录和文件
 os.getcwd():获得当前工作目录
 os.curdir:返回当前目录('.')
 os.chdir(dirname):改变工作目录到dirname
 os.path.isdir(name):判断name是不是目录,不是目录就返回false
 os.path.dirname(name):返回文件所在的目录
 os.path.isfile(name):判断name这个文件是否存在,不存在返回false
 os.path.exists(name):判断是否存在文件或目录name
 os.path.getsize(name):或得文件大小,如果name是目录返回0L
 os.path.abspath(name):获得绝对路径
 os.path.isabs():判断是否为绝对路径
 os.path.normpath(path):规范path字符串形式
 os.path.split(name):分割文件名与目录(事实上,如果你完全使用目录,它也会将最后一个目录作为文件名而分离,同时它不会判断文件或目录是否存在)
 os.path.splitext():分离文件名和扩展名
 os.path.join(path,name):连接目录与文件名或目录
 os.path.basename(path):返回文件名
 os.path.dirname(path):返回文件路径
 import os
def path1(file1,match1=os.sep):
	
	# abspath1=(os.path.abspath(__file__))
	dir1=os.path.dirname(file1)
	if dir1.endswith(os.sep) is True:
		return dir1
	else:
		return dir1+os.sep
abspath1=(os.path.abspath(__file__))
print(path1(abspath1))
 2.关于class 类继承学习 包括在类函数中用raise NotImplementedError的学习 class animal(object):
	def __init__(self,name,age):
		self.name=name
		self.age=age
	def call(self):
		print(self.name+'is saying Hello')
	def sit(self):
		raise NotImplementedError
class cat(animal):
	def __init__(self,name,age,sex):
		super(cat,self).__init__(name,age)
		self.sex=sex
	def sit(self):
		print(self.name+' is sitting down')
# a=animal('dog','25')
# a.call()
# a.sit()
b=cat('dog','25','male')
b.call()
b.sit()
 程序定义两个类,animal基类,cat继承animal类,其中super(cat,self).__init__(name,age)是用来继承animal类的变量 当 继承的类 子函数sit没有重新定义的话,就会激发raise NotImplementedError错误 Traceback (most recent call last):? File "C:\Users\weijiangbin\Desktop\python_learning\test20210503.py", line 78, in <module>
 ? ? b.sit()
 ? File "C:\Users\weijiangbin\Desktop\python_learning\test20210503.py", line 59, in sit
 ? ? raise NotImplementedError
 NotImplementedError
 只有定义了函数的话才不会报错,大家可以试下 3.函数中定义输入参数和输出参数的类型 def add1(a:int,b:int)->int:
	return a+b
c=1
d=3
print(add1(c,d))
 如上文中,add1函数a,b强制定义为int类型,同时输出用->int定义为int类型输出 4.isinstance取代type定义类型对比 class animal(object):
	def __init__(self,name,age):
		self.name=name
		self.age=age
	def call(self):
		print(self.name+'is saying Hello')
	def sit(self):
		raise NotImplementedError
class cat(animal):
	def __init__(self,name,age,sex):
		super(cat,self).__init__(name,age)
		self.sex=sex
	def sit(self):
		print(self.name+' is sitting down')
a=animal('dog','25')
a.call()
# a.sit()
b=cat('dog','25','male')
b.call()
b.sit()
print(isinstance(a,animal))
print(type(a)==animal)
print(isinstance(b,animal))
print(type(b)==animal)
 结果为 |