Wonderland of C++

不要做一个浮躁的人

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  13 随笔 :: 1 文章 :: 0 评论 :: 0 Trackbacks
111
import sys
def readfile(filename):
        
'''Print a file the standard output.'''
        f 
= file(filename)
        
while True:
                line 
= f.readline()
                
if len(line) == 0:
                        
break
                
print line, #notice comma
        f.close()

if len(sys.argv) < 2:
        
print 'No action specified.'
        sys.exit()

if sys.argv[1].startswith('--'):
        option 
= sys.argv[1][2:]
        
if option == 'verison':
                
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 : Print the version number
        --help    : Display this help
'''
                
else:
                
print 'Unknown option.'
                sys.exit()
else:
        
for filename in sys.argv[1:]:
                readfile(filename)
运行提示:
D:\python>python cat.py
  File "cat.py", line 27
    else:
       ^
SyntaxError: invalid syntax

谁知道这个哪里出错了啊


Robert Su 2008-08-15 17:41 发表评论

文章来源:http://www.blogjava.net/babymouse/archive/2008/08/15/222312.html
posted on 2008-08-15 17:41 Robert.Su 阅读(295) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理