Home
Sign Up
Sign In
推荐学习书目
›
Learn Python the Hard Way
Python Sites
›
PyPI
- Python Package Index
›
http://diveintopython.org/toc/index.html
›
Pocoo
值得关注的项目
›
PyPy
›
Celery
›
Jinja2
›
Read the Docs
›
gevent
›
pyenv
›
virtualenv
›
Stackless Python
›
Beautiful Soup
›
结巴中文分词
›
Green Unicorn
›
Sentry
›
Shovel
›
Pyflakes
›
pytest
Python 编程
›
pep8 Checker
Styles
›
PEP 8
›
Google Python Style Guide
›
Code Style from The Hitchhiker's Guide
V2EX
›
Python
stdin 如何能自动判断
rockyaow
·
Jul 29, 2014
· 3937 views
This topic created in 4373 days ago, the information mentioned may be changed or developed.
我写了个脚本,想支持用Linux 管道(|)方式传参数进去
但是如果直接用sys.stdin.read去读,程序就卡住了,显然这个方法是不正确的。
怎么能自动判断调用脚本的时候是否使用了管道?从而再去读stdin呢?
stdin
脚本
管道
4 replies
•
2014-07-30 10:15:18 +08:00
1
qq529633582
Jul 29, 2014
1
isTTY()
2
heiher
Jul 29, 2014 via iPhone
可以要求参数为-的时候读stdin,如 vim a.txt 访问文件,而 vim - 就访问 stdin。
3
bombless
Jul 30, 2014
同意@
heiher
的。
判断是不是管道比较像Windows风格而不是*nix
4
rockyaow
OP
Jul 30, 2014
谢谢各位,sys.stdin.isatty 确认可行
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Solana
·
1314 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 37fae26a · 44ms ·
UTC 16:52
·
PVG 00:52
·
LAX 09:52
·
JFK 12:52
♥ Do have faith in what you're doing.
❯