#!usr/bin/python
# Filename: test4.py
import sys
def readfile(filename):
'''Print a file to the standard output.'''
f = open(filename)
while True:
line = f.readline()
if len(line) == 0:
break
print line, # notice comma
f.close()
# Script starts from here
if len(sys.argv) < 2:
print 'No action specified.'
sys.exit()
if sys.argv[1].startswith('>>'): #就是把这个地方改了
option = sys.argv[1][2:]
# fetch sys.argv[1] but without the first two characters
if option == 'version':
print 'Version 1.2'
elif option == 'help':
print '''\
This program prints files to the standard output.
Any number of files can be specified.
Options include:
--version : Prints the version number
--help : Display this help'''
else:
print 'Unknown option.'
sys.exit()
else:
for filename in sys.argv[1:]:
readfile(filename)
我把它改成‘>>’以後,输进去设麼都没发生:
[Do.Lee@luoluo0 mission_1]$ python test4.py ==version
Version 1.2
[Do.Lee@luoluo0 mission_1]$ python test4.py >>version
[Do.Lee@luoluo0 mission_1]$
那我要怎麼弄才能把'>'传过去啊?
python简明教程裏sys.argv的用法,为什恶我把“--”改成“>>”以後就没有输出了的?而把它改成“==“就行
答案:2 悬赏:20 手机版
解决时间 2021-03-01 19:22
- 提问者网友:饥饿走向夜
- 2021-03-01 13:52
最佳答案
- 五星知识达人网友:迟山
- 2021-03-01 15:24
>>
这个在操作系统中是重定向的格式,操作系统不会把它解析成参数传递给程序。
这个在操作系统中是重定向的格式,操作系统不会把它解析成参数传递给程序。
全部回答
- 1楼网友:冷風如刀
- 2021-03-01 16:13
虽然我很聪明,但这么说真的难到我了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯