标准库sys模块

标准库sys模块

官方文档:https://docs.python.org/3/library/sys.html

(1)stdin

从标准输入读入数据

import sys
text = sys.stdin.read()
words = text.split("-")
for i in words:
    print(i)

要得到返回结果,需要按 CTRL+D 才能返回。

因为 read读取数据 ctrl+d是结束输入 ,read并不会像input那样遇到回车就返回读取的数据
它会缓存。

text = input("")
for i in text:
    print(i)
(2)argv

获取程序外部向程序传递的参数

import sys
print(sys.argv[0])
print(sys.argv[1])

对比一下bash shell:

#!/bin/bash
echo "number:$#"
echo "scname:$0"
echo 

猜你喜欢

转载自blog.csdn.net/knight_zhou/article/details/106940614