Python OS/OS.PATH/Built-in 常用函数

本文详细介绍了Python中文件操作、路径管理的相关API及用法,包括获取平台信息、文件路径操作、文件属性获取与判断等核心内容,旨在帮助开发者高效地进行文件相关操作。
import os

#获取平台名字
print os.name

#获取当前工作目录
print os.getcwd();

#获取环境变量Key
print os.getenv();

#添加环境变量Name/value
print os.putenv();

#删除一个文件
print os.remove();

#平台的换行符
print os.linesep;

import os.path



#活的绝对路径
print os.path.abspath("data.xml");import platform

#获取路径和当前脚本的所在目录
print os.path.split(os.getcwd());

#添加路径
print os.path.join(os.getcwd(),"keeper");

#判断文件是否存在
print os.path.exists(os.path.abspath("data.xml"));

#获取文件创建时间
print os.path.getctime(os.path.abspath("data.xml"));

#获取文件大小
print os.path.getsize(os.path.abspath("data.xml"));

#判断是否是文件
print os.path.isfile(os.path.abspath("data.xml"));

#判断是否是目录
print os.path.isdir(os.path.abspath("data.xml"));

#获取路径和脚本后缀名
print os.path.splitext(os.path.abspath("data.xml"));

#获取文件修改的时间
print os.path.getmtime(os.path.abspath("data.xml"));

#最后访问的时间
print os.path.getatime(os.path.abspath("data.xml"));
#求绝对值
print abs(-1);

#返回列表最大的元素
print max([1,2,3,4]);

#返回列表最小的元素
print min([1,2,3,4]);

#获取x地址
print id(x);

#获取长度
print len([1,2,3]);

#返回当前文件的变量字典
print locals();

#获取当前脚本地址
print __file__;

#返回类型
print type(x);


[ 99%] Built target xyber_x1_infer_my_proto_pb_gencode running egg_info writing my_ros2_proto.egg-info/PKG-INFO writing dependency_links to my_ros2_proto.egg-info/dependency_links.txt writing top-level names to my_ros2_proto.egg-info/top_level.txt [ 99%] Running protoc, args: --proto_path=/home/byd/X1/agibot_x1_infer-main/build/_deps/aimrt-src/src/protocols/sensor --proto_path=/home/byd/X1/agibot_x1_infer-main/build/_deps/aimrt-src/src/protocols/common;--proto_path=/home/byd/X1/agibot_x1_infer-main/build/_deps/protobuf-src/src --cpp_out=/home/byd/X1/agibot_x1_infer-main/build/_deps/aimrt-build/src/protocols/sensor /home/byd/X1/agibot_x1_infer-main/build/_deps/aimrt-src/src/protocols/sensor/image.proto reading manifest file 'my_ros2_proto.egg-info/SOURCES.txt' writing manifest file 'my_ros2_proto.egg-info/SOURCES.txt' /usr/bin/ld: skipping incompatible /home/byd/X1/agibot_x1_infer-main/src/module/joy_stick_module/third_party/lib/libqpOASES.so when searching for -lqpOASES /usr/bin/ld: cannot find -lqpOASES: No such file or directory /usr/bin/ld: skipping incompatible /home/byd/X1/agibot_x1_infer-main/src/module/joy_stick_module/third_party/lib/libqpOASES.so when searching for -lqpOASES /usr/bin/ld: skipping incompatible /home/byd/X1/agibot_x1_infer-main/src/module/control_module/third_party/lib/libruckig.so when searching for -lruckig /usr/bin/ld: cannot find -lruckig: No such file or directory /usr/bin/ld: skipping incompatible /home/byd/X1/agibot_x1_infer-main/src/module/control_module/third_party/lib/libruckig.so when searching for -lruckig [100%] Building CXX object _deps/aimrt-build/src/protocols/sensor/CMakeFiles/aimrt_protocols_sensor_pb_gencode.dir/image.pb.cc.o [100%] Built target ament_cmake_python_build_my_ros2_proto_egg /usr/bin/ld: skipping incompatible /home/byd/X1/agibot_x1_infer-main/src/module/control_module/third_party/lib/libonnxruntime.so when searching for -lonnxruntime /usr/bin/ld: skipping incompatible /home/byd/X1/agibot_x1_infer-main/src/module/sim_module/third_party/lib/libmujoco.so when searching for -lmujoco /usr/bin/ld: cannot find -lmujoco: No such file or directory /usr/bin/ld: skipping incompatible /home/byd/X1/agibot_x1_infer-main/src/module/sim_module/third_party/lib/libmujoco.so when searching for -lmujoco collect2: error: ld returned 1 exit status gmake[2]: *** [src/pkg/pkg1/CMakeFiles/xyber_x1_infer_pkg1.dir/build.make:248: libpkg1.so] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:3121: src/pkg/pkg1/CMakeFiles/xyber_x1_infer_pkg1.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs.... [100%] Linking CXX static library ../../../../../libaimrt_protocols_sensor_pb_gencode.a [100%] Built target aimrt_protocols_sensor_pb_gencode gmake: *** [Makefile:166: all] Error 2 byd@ubuntu:~/X1/agibot_x1_infer-main$
06-10
/Users/liuyangbin/safeheron/.venv/bin/python /Applications/PyCharm.app/Contents/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py --path /Users/liuyangbin/safeheron/q.py Testing started at 16:11 ... Launching pytest with arguments /Users/liuyangbin/safeheron/q.py --no-header --no-summary -q in /Users/liuyangbin/safeheron ============================= test session starts ============================== collecting ... 3 function calls in 0.000 seconds Ordered by: standard name ncalls tottime percall cumtime percall filename:lineno(function) 1 0.000 0.000 0.000 0.000 <string>:1(<module>) 1 0.000 0.000 0.000 0.000 {built-in method builtins.exec} 1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects} q.py:None (q.py) q.py:9: in <module> cProfile.run('test_function()') /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/cProfile.py:16: in run return _pyprofile._Utils(Profile).run(statement, filename, sort) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/profile.py:53: in run prof.run(statement) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/cProfile.py:95: in run return self.runctx(cmd, dict, dict) /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/cProfile.py:100: in runctx exec(cmd, globals, locals) <string>:1: in <module> ??? E NameError: name 'test_function' is not defined collected 0 items / 1 error !!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!! =============================== 1 error in 0.07s =============================== Process finished with exit code2
11-04
Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/__init__.py", line 76, in __getattr__ from . import torchair File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/torchair/__init__.py", line 5, in <module> from torchair.npu_fx_compiler import get_compiler File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/torchair/npu_fx_compiler.py", line 28, in <module> from torchair.ge._ge_graph import is_sym, _torch_tensor_to_ge_const File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/torchair/ge/__init__.py", line 1, in <module> from torchair.ge.ge_custom import custom_op File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/torchair/ge/ge_custom.py", line 4, in <module> from torchair._ge_concrete_graph.compat_ir import ge_op File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/torchair/_ge_concrete_graph/compat_ir.py", line 5, in <module> from torchair.core import _torchair ImportError: /usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/torchair/core/_abi_compat_ge_apis.so: undefined symbol: _ZN2ge5Graph28LoadFromSerializedModelArrayEPKvm The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/root/ModelZoo-PyTorch/ACL_PyTorch/built-in/audio/SenseVoice/TorchAir/FunASR/infer.py", line 33, in <module> npu_backend = tng.get_npu_backend(compiler_config=config) File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/__init__.py", line 66, in __getattr__ return self._exception() File "/usr/local/lib/python3.10/dist-packages/torch_npu/dynamo/__init__.py", line 39, in __call__ raise self._info from self._e torch_npu.dynamo._TorchairImportError: An error occured when import `torchair` and the above is the specific error message. This error message was generated when import torchair, but throwed asynchronously here. Please check the error message above. [ERROR] 2025-12-03-10:48:35 (PID:1333232, Device:-1, RankID:-1) ERR00005 PTA internal error /usr/lib/python3.10/tempfile.py:1008: ResourceWarning:
最新发布
12-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值