Python basics-People's Favorite standard library (sys OS fileinput)

Source: Internet
Author: User

This blog introduces the standard libraries in common, beloved Python.

SYS
It can be literally seen as the abbreviation for the system. This module provides access to variables and functions that are closely related to the Python parser.

argv     命令行参数exit     退出当前程序modules  映射模块名到载入模块的字典path     目录platform 平台标识符stdin    标准输入stdout   标准输出stderr   标准错误流

Apply, reverse Print command name parameter:

import sysargs = sys.argv[1:]args.reverse()print ‘ ‘.join(args)

OS
OS is the operating system.
The following are more important:

environ     对环境变量进行映射system      在子shell中执行操作系统命令sep         路径中的分隔符pathsep     分隔路径的分隔符linesep     行分隔符urandom     返回n字节的加密强随机数据

Fileinput
Working with files

input        便于遍历多个输入流中的行filename()   返回当前文件的名称lineno() 返回当前累计的行数filelineno() 返回当前文件的行数isfirstline()检查当前行是否是文件中的第一行isstdin() 检查最后一行是否来自sys.stdinnextfile() 关闭当前文件,移动到下一个文件close() 关闭序列

App, add line numbers for Python scripts:

impotr fileninputfor line in fileninput.input(inplace = True):  line = line.rstrip() num = fileinput.lineno() print ‘%-40s # %2i ‘ % (line, num)

Python basics-People's Favorite standard library (sys OS fileinput)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.