python notes(1)

本文介绍了Python中关于命令行参数传递、源代码编码以及标准库的使用等核心概念。包括如何处理命令行输入、使用UTF-8编码、以及利用os、glob、sys模块进行文件操作和系统交互等内容。

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

[size=medium]1. Argument passing:
When known to the interpreter, the script name and additional arguments thereafter are passed to the script in the variable sys.argv, which is a list of strings. Its length is at least one; when no script and no arguments are given, sys.argv[0] is an empty string. When the script name is given as '-' (meaning standard input), sys.argv[0] is set to '-'. When -c command is used, sys.argv[0] is set to '-c'. When -m module is used, sys.argv[0] is set to the full name of the located module. Options found after -c command or -m module are not consumed by the Python interpreter’s option processing but left in sys.argv for the command or module to handle.

2. Source Code Encoding
# -*- coding: utf-8 -*-
by using UTF-8 (either through the signature or an encoding declaration), characters of most languages in the world can be used simultaneously in string literals and comments. Using non-ASCII characters in identifiers is not supported. To display all these characters properly, your editor must recognize that the file is UTF-8, and it must use a font that supports all the characters in the file.

3.Brief Tour of the Standard Library
The os module provides dozens of functions for interacting with the operating system:
The glob module provides a function for making file lists from directory wildcard searches
Command Line Arguments are stored in the sys module’s argv attribute as a list.
The sys module also has attributes for stdin, stdout, and stderr. The latter is useful for emitting warnings and error messages to make them visible even when stdout has been redirected:
The re module provides regular expression tools for advanced string processing.
The math module gives access to the underlying C library functions for floating point math
The random module provides tools for making random selections
There are a number of modules for accessing the internet and processing internet protocols. Two of the simplest are urllib2 for retrieving data from urls and smtplib for sending mail:
The datetime module supplies classes for manipulating dates and times in both simple and complex ways.
Common data archiving and compression formats are directly supported by modules including: zlib, gzip, bz2, zipfile and tarfile.
[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值