通过代码实例了解Pythonsys模块-创新互联

sys-系统特定的参数和功能

成都创新互联公司专注于廉江企业网站建设,成都响应式网站建设公司,电子商务商城网站建设。廉江网站建设公司,为廉江等地区提供建站服务。全流程按需网站建设,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务

该模块提供对解释器使用或维护的一些变量的访问,以及与解释器强烈交互的函数。它始终可用。

代码如下

#!/usr/bin/python
# Filename: cat.py

import sys

def readfile(filename):
  '''Print a file to the standard output.'''
  f = file(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)

文章题目:通过代码实例了解Pythonsys模块-创新互联
标题网址:https://www.cdcxhl.com/article42/jspec.html

成都网站建设公司_创新互联,为您提供虚拟主机定制开发网站制作营销型网站建设云服务器手机网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设