Python标准库——简明python教程学习笔记

本文基于简明Python教程和官方文档,探讨Python标准库的sys和os模块。sys模块提供访问解释器变量和功能的途径,如sys.argv用于获取命令行参数。os模块则包含跨平台的系统功能,如os.getcwd()获取当前工作目录,os.listdir()列出目录内容。文章介绍了在不同环境下使用sys.argv遇到的问题及解决方案,并强调了os模块在实现平台无关性中的作用。

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

Python标准库——简明python教程学习笔记

本文大量内容来源于沈老师的简明python教程和python官方的解释文档https://docs.python.org/3/library/sys.html,其中夹杂部分个人的理解如有偏颇之处还望海涵。

简介

\quad Python标准库是随Python附带安装的,它包含大量极其有用的模块。熟悉Python标准库是十分 重要的,因为如果你熟悉这些库中的模块,那么你的大多数问题都可以简单快捷地使用它们来解决。

sys模块

This module provides access to some variables used or maintained by
the interpreter and to functions that interact strongly with the
interpreter. It is always available.

sys.argv

The list of command line arguments passed to a Python script.
argv[0] is the script name (it is operating system dependent whether
this is a full pathname or not). If the command was executed using the
-c command line option to the interpreter, argv[0] is set to the string ‘-c’. If no script name was passed to the Python interpreter,
argv[0] is the empty string.

传递给Python脚本的命令行参数列表。
argv [0]是脚本名称(无论这是否是完整路径名,它依赖于操作系统)。 如果使用解释器的-c命令行选项执行命令,则将argv [0]设置为字符串’-c’。 如果没有脚本名称传递给Python解释器,则ar

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值