os.path.abspath 源码分析

os.path.abspath() 函数返回规范化后的绝对路径。当在Windows上时,它可能使用_win32API的_getfullpathname接口。如果路径为空,则会返回当前工作目录。在非Windows系统中,它将路径与当前工作目录合并。源码分析涉及isabs()、getcwdu()、getcwd()和join()等函数的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

os.path.abspath(path) 官方文档的介绍:

Return a normalized absolutized version ofthe pathname path. On most platforms, this is equivalent to callingthefunction normpath() asfollows:normpath(join(os.getcwd(), path)).

New in version 1.5.2.

这个函数会返回标准化的绝对路径。在大多数平台,它等同于normpath(join(os.getcwd(), path)).,这个后文的源码中会讲到

应用场景:

import io import os import re import setuptools def get_long_description(): base_dir = os.path.abspath(os.path.dirname(__file__)) with io.open(os.path.join(base_dir, "README.md"), encoding="utf-8") as f: return f.read() def get_requirements(): with open("requirements.txt", encoding="utf8") as f: return f.read().splitlines() def get_version(): current_dir = os.path.abspath(os.path.dirname(__file__)) version_file = os.path.join(current_dir, "sahi", "__init__.py") with io.open(version_file, encoding="utf-8") as f: return re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', f.read(), re.M).group(1) setuptools.setup( name="sahi", version=get_version(), author="OBSS", license="MIT", description="A vision library for performing sliced inference on large images/small objects", long_description=get_long_description(), long_description_content_type="text/markdown", url="https://github.com/obss/sahi", packages=setuptools.find_packages(exclude=["demo", "docs", "resources", "tests", "scripts"]), python_requires=">=3.6", install_requires=get_requirements(), extras_require={ "tests": ["mmdet==3.0.0", "pycocotools==2.0.6"], "dev": [ "black==22.3.0", "flake8==3.9.2", "importlib-metadata>=1.1.0,<4.3;python_version<'3.8'", "isort==5.9.2", "jupyterlab==3.0.14", ], }, classifiers=[ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", ], entry_points={ "console_scripts": [ "sahi=sahi.cli:app", ], }, ) 解读代码
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值